09-25-2008, 12:29 AM
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:
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.
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:
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.
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
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
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.