Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: Delete an array, destroy a dialog box?
Topic Summary: Memory cleanup....
Created On: 9-Feb-2007 12:53
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by David Pechacek, on Friday, February 9, 2007 8:27 PM

Answer:

 

 9-Feb-2007 12:53
User is offline View Users Profile Print this message


Brant Stoner

Posts: 30
Joined: 2-Aug-2004

I have a DXL script which populates an array. The script then shows a dialog box that displays information from the array. Since I'm using the "show" function to display the dialog, none of the DXL after the "show" function gets executed. I still need the array while the dialog is displayed....so how do I delete the array once the dialog box is closed (and similarly, how do I destroy the dialog box) to free up memory? Do I even need to, or is the memory reclaimed when the DXL script stops running?

I tried creating a callback function for the "Close" button to do these things, but I crashed DOORS repeatedly. Any advice would be helpful. Maybe my callback function is just not 100% correct...?

Thanks,
Brant
Report this to a Moderator Report this to a Moderator
 9-Feb-2007 15:41
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

Answer Answer

 



-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com

Edited: 9-Feb-2007 at 15:43 by David Pechacek
Report this to a Moderator Report this to a Moderator
 9-Feb-2007 20:28
User is offline View Users Profile Print this message


Brant Stoner

Posts: 30
Joined: 2-Aug-2004

Worked like a charm. Not sure what I was doing wrong in my original callback.

Thanks!
Report this to a Moderator Report this to a Moderator
 13-Feb-2007 01:27
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Maybe you can help me out here. I hardly ever use the 'close' function since I've always presumed that once the Dialog closes that all the space used by its scripts is also freed up, specifically all the Buffers, Skip lists, Arrays, and whatever space the Dialog uses. And if that's so I never use the 'destroy' function.

Your question seems to suggest that you know otherwise, and I was wondering if perhaps you could tell me how or what you know otherwise.

- Louie
Report this to a Moderator Report this to a Moderator
 13-Feb-2007 11:25
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

Interesting point Louie, I religously use delete(), destroy() etc on all data structures and dialogs. But as you say, the script is ending, so this may not indeed be necessary.

My tests show that ending the script, by closing the dialog, does indeed free-up memory used by data structures.

-------------------------
Tony Goodman
http://www.smartdxl.com
Report this to a Moderator Report this to a Moderator
 13-Feb-2007 13:36
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

I just do it as good programming practice.  Yes DXL is bad about releasing back memory prior to the end of the script and should release all the memory back regardless of doing destroy, delete, etc at the end.  However I've come to not rely on languages doing things for me and instead just doing them myself. 

But yes, at the end of the script, calling destroy on a dialog box and buffer does seem redundant.  But inside a loop, deleting a buffer or dialog box can help cut down on memory usage it seems.  Some of the scripts I've done so far have looped through numerous modules and I've managed to keep the memory usage steady during them.  Whether this is from DXL or my using those destroy and delete functions, I don't know.  But I'll keep using them just in case.

I'm still waiting for a flushMem() function though that frees up unused but allocated memory. Submit those product enhancements!

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 13-Feb-2007 22:58
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

I of course routinely deleted data structures at the bottom of a function when that structure was created at the top. However, I'm in the dubious habit of often using global data structures that are created at script startup and never deleted. Consider the following libary function:

string MakeLine(string Field1, Field2)
{ // Put the fields together
Buffer bufResults = create()
bufResults += Field1
bufResults += "\t"
bufResults += Field2
bufResults += "\n"
string Temp = stringOf(bufResults)
delete(bufResults)
return(Temp)
} // end MakeLine()

This function is quite a bit faster when coded this way:

Buffer gn_bufMakeLine = create() // Local buffer for the following MakeLine()
string MakeLine(string Field1, Field2)
{ gn_bufMakeLine = Field1 // =, erases what's there if anything
gn_bufMakeLine += "\t"
gn_bufMakeLine += Field2
gn_bufMakeLine += "\n"
return(stringOf(gn_bufMakeLine))
} // end MakeLine

Notice the function doesn't waste time creating and deleting the buffer.

I've of course noticed serious memory leak in long running DXL that gets better when the script ends. Specifically, the last 10 modules of a batch of 100 takes a lot longer than the first 10. Its usually better to chunk the chore up into 4 groups of 25.

However, I've also noticed that I'm often better off exiting DOORS and restarting it after some of my long running DXL are finished, suggesting that they are leaving inefficiencies even after they end. Thus I figure perhaps I'm doing something wrong and hence my question.

- Louie
Report this to a Moderator Report this to a Moderator
 14-Feb-2007 14:18
User is offline View Users Profile Print this message


David Pechacek

Posts: 674
Joined: 5-Dec-2006

No.  I also have to do that.  If I run a very large/long script, I also find that exiting DOORS and restarting improves the speed of it.

-------------------------
David Pechacek
AAI Services Textron
dpechacek@sc-aaicorp.com
David.Pechacek@gmail.com
Report this to a Moderator Report this to a Moderator
 14-Feb-2007 19:14
User is offline View Users Profile Print this message


Brant Stoner

Posts: 30
Joined: 2-Aug-2004

I'm uncertain how the DXL engine handles arrays and dialogs when the script ends, but the reason I asked was because somewhere in the DXL manual (I think it was in the section on arrays) there was a comment to the effect that "DXL doesn't clean up after itself, so use the delete() function when you're done with an array to free up memory." I believe the term "garbage collection" was used ("garbage" would certainly describe a lot of my DXL scripts....)

I wasn't sure whether or not this stuff was automatically taken care of at the end of the DXL script execution. On the one hand, I would expect that once the script is done running all the memory it was using would be freed, but on the other hand, if that were the case then the delete() function would be more of a "good coding practice" then a "call it unless you like seeing your memory contents blasted across the screen when DOORS self destructs", as the warning in the manual seems to suggest.
Report this to a Moderator Report this to a Moderator
 15-Feb-2007 05:45
User is offline View Users Profile Print this message


Louie Landale

Posts: 2070
Joined: 12-Sep-2002

Deleting when done gives the benefit to the current script. Imagine the space used up by a script that compares Object Text of every object in every requirement module of a big folder, with the Text of its linked partners? Yes you'd use a lot of local Buffers and these would stack up right quick if you didn't remove them when done. Look at this:

void DisplayDifferences(Object oOld, oNew)
{ Buffer bufOld = create()
Buffer bufNew = create()
Buffer bufDiff = create()

bufOld = oOld."Object Text"
bufNew = oNew."Object Text"
diff(bufDiff, bufOld, bufNew)
oNew."Baseline Diffs" = richText(bufDiff)
}

Notice it doesn't delete its buffers. Such a function will quickly drag any parent script down to a halt if called a bunch of times.

- Louie
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 2 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 2 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.