Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clear memory of an object properly between loop iterations?
#1
Solved: 11 Years, 4 Months 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
#2
Solved: 11 Years, 4 Months ago
Can you end the iterations one by one .so that the values are not moved fro mthe frst iteratio nto the second
Reply
#3
Solved: 11 Years, 4 Months ago
How do you mean "end the iterations one by one"? Could you give an example how to do this in practise?
Reply
#4
Solved: 11 Years, 4 Months ago
Append
Code:
oDesc.Quit
just before
Code:
Set oDesc = Nothing
  Set List = Nothing

Let me know if that worked.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#5
Solved: 11 Years, 4 Months ago
I have pasted "oDesc.Quit" before "Set oDesc = Nothing" but I get a run error window with the text:

"Object doesn't support this property: 'oDesc.Quit'"
Reply
#6
Solved: 11 Years, 4 Months ago
ok, The concept behind this is if any of the instance(copy) of the created object is LIVE(ie the pointer to the object) then the object would not be destroyed...you need to make sure that while passing ByRef ALL the instances are set to Nothing in the end.

In your case parentnode may be the problem point.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply


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 973 04-23-2020, 07:08 PM
Last Post: BGunay
  Repeat iterations Until New Value Is Seen in Column1 shayk1985 1 1,745 07-05-2018, 05:52 PM
Last Post: Ankur
  UFT Datatable iterations Studymode 2 3,799 12-12-2017, 11:10 PM
Last Post: Studymode
  QTP-Re-executing script after completion of all iterations JwalantBhatt0602 1 2,696 03-24-2016, 12:37 AM
Last Post: JwalantBhatt0602
Question QTP not performing iterations based on local data sheet Breaker 18 56,762 01-25-2016, 04:32 PM
Last Post: arunshuklainbox

Forum Jump:


Users browsing this thread: 2 Guest(s)