Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clear memory of an object properly between loop iterations?
#1
Solved: 10 Years, 9 Months, 3 Weeks ago
I have a question regarding cleaning the memory of objects properly between after the first iteration of a loop.

In my QTP script I call a function in order to collect WebElement objects via ChildObjects in order to click on a link in a Table Of Content (TOC) of WebElement objects. Simplified the TOC structure looks like this:
Code:
Table of contents on screen 1st iteration when going into openBranch function (see code further down):

1 RootA ->
          11 BranchA
          12 BranchB
2 RootB
3 RootC
I My script begins to open "1 RootA" in the first iteration and then "2 RootB" in the next iteration. As you see the in the code below I start to call a function that closes each of the levels so the TOC is completely closed before the opening of the levels begin.
Code:
For i = 1 To 5
  closeOpenTocLevels(parentFrame) 'Begins to look at the last level, this is done after the first iteration
  openRoot(parentFrame)
  openBranch(parentFrame)
Next

Function openBranch(ByRef parentNode)
  'Create Object with properties that fit the Root1 link names and send them to ChildObjects
  Set oDesc = Description.Create()
  oDesc("micclass").Value="WebElement"
  oDesc("innertext").Value="[0-9]+[0-9].*" (this is the name of the link that starts with two digits)
  ...
  Set List = parentNode.ChildObjects(oDesc)
  NoOfChildren = List.Count
  'Click on selected List link
  ...
  Set oDesc = Nothing
  Set List = Nothing
End Function
In the first iteration the following collection of objects is found in openBranch via "Set List = parentNode.ChildObjects(oDesc)":

11 BranchA
12 BranchB

This is correct since they are the only objects that fits the Object property.

My problem is that when going into the second iteration of the For-Next loop, the List objects that was collected via ChildObjects in the first iteration are now included in the collection again even though they are not shown on the screen as seen below:
Code:
Table of contents on screen 2nd iteration when going into openBranch function:

1 RootA
2 RootB ->
           21 BranchC
           22 BranchD
3 RootC

The collection of objects found via "Set List = parentNode.ChildObjects(oDesc)" are the following:

11 BranchA
12 BranchB
21 BranchC
22 BranchD

The question is why the objects from the first iteration are collected when they are not appearing on the screen when sending oDesc to ChildObjects? A guess is that they are saved in the object memory, so how do I clean the memory properly before going into the second iteration? I set "oDesc = Nothing" and "List = Nothing" at the end of the function, but obviously that isn't enough.
Reply


Messages In This Thread
Clear memory of an object properly between loop iterations? - by MGMN - 09-25-2008, 12:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Object not found during the 2nd iteration of an Action call in a For loop BGunay 0 862 04-23-2020, 07:08 PM
Last Post: BGunay
  Repeat iterations Until New Value Is Seen in Column1 shayk1985 1 1,519 07-05-2018, 05:52 PM
Last Post: Ankur
  UFT Datatable iterations Studymode 2 3,506 12-12-2017, 11:10 PM
Last Post: Studymode
  QTP-Re-executing script after completion of all iterations JwalantBhatt0602 1 2,562 03-24-2016, 12:37 AM
Last Post: JwalantBhatt0602
Question QTP not performing iterations based on local data sheet Breaker 18 55,378 01-25-2016, 04:32 PM
Last Post: arunshuklainbox

Forum Jump:


Users browsing this thread: 1 Guest(s)