Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form unload does not release memory! 1

Status
Not open for further replies.

sohelcse

Programmer
Jul 22, 2001
2
BD
We have an MDI application with 30 child forms. 'Orders' form is loaded from menu using this command - frmOrders.show. When user presses a 'Close' button in the form, the form closes by calling Unload Me. Keeping the Win2K Task Manager open, I watched that before the form is shown the program was using 6M of memory. After the form
is shown the used memory becomes 7.8 MB. Now when the form is unloaded, it still is showing the same memory use! But subsequent call to the same form does not use any extra memory.

I searched through the newsgroup and saw a solution which says - 'set frmOrders = Nothing' statement will release the memory back to windows. But IT IS NOT TRUE. I tried with a small program with two forms but found no truth in it.

After each form is shown, the memory use increases and the program starts slowing down. Any solutions?

I am using:
Windows 2000 Professional
Visual Basic 6 (+SP5)
 
>Unload does take the form out of th Forms Collection even though there are other references as I showed above

JohnYingling: I realize this...
Therefore my previous post on it as well

But sohelcse needs to take this as a start, as well as opening the forms and shutting them down properly by setting them to nothing, amongst checking the termination AND initialization, to make sure for every initialization event there was a terminate event, as I also mentioned.

Initialized/terminated is different to Loaded/unloaded.

In each form's Initialize event put:
Debug.Print "form1 has Initialized"

And in each terminate event put:
Debug.Print "form1 has Terminated"


Yea, I guess one sentence was mis-understood.[smile]


[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

There is enough stuff here for the questioner to ponder on and study.

Just a matter of experimenting on her/his own, especially with the init/terminate events.

Therefore I am leaving it at that for now.
There is no need to pursue this further with-out knowing more - and that would mean having to review the complete application in order to figure out what is being done wrong and where.

There are some basic guidelines to follow however, as many books point out (and many don't), as well as through out this forum, and even (forgive for saying it) the "VB Project Wizard" will give a weak idea to a beginner as to how to do the minimum.

You need to test alot on your own and see what is happening, especially in matters such as this.

I can only say, among the other guidlines from above, to stay away from referencing a form with-out using a variable you have created, which is set, and not declared as new, and do not use the NEW keyword in the Declaration section of a class or module, but SET it explicitly.
Keep track of all your references to public objects, and make sure they are shut down.

And set those public object variables to nothing.

Use the Initialize/terminate events to make sure all forms get terminated, and if it doesn't happen, start searching as to what you have done differently to prevent it from happening.


[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
CCLint

Soory if I misunderstood. It seems that some people, not you, are focusing on the Unload. Unload is a piece of cake. A form will ALWAYS unload if you go through the Form_Unload event without cancelling. the fact that a form is no longer in the Forms Collection does not mean that the form has terminated. The "trick" is to get the form to terminate (I know you know that) by eliminating all references to the form, even in the form itself and of of its MDI children, if any.

Sohelcse

Is it possible that you have any references in your MDI child form to the MDI main form or an controls on the main form, like a progress bar? If so, it must be set to Nothing before unloading the MDI child or in the Unload event itself. Circular references are a beach...upon which many run aground. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
JohnYingling

Yes, I guess we all say at times "Unloaded" when we mean terminated, and other times "Unloaded" when we mean Unloaded.

And I see after really reading your initial posts (sorry) that you already did hit on concerning init/terminate/unload.

Looks like I was just repeating alot of it...[sleeping]
[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top