memory management

harvid

Member
Joined
Dec 8, 2004
Messages
18
Programming Experience
1-3
In vb.net if i open a single form in my application ,the memory gets increased ,likewise when i close the form the memory is not getting released why so? I want to release the memory.Is there any way to clear off the memory once i close the form?


The memory gets accumulated whenever i close the form2 and reopen form2 thru form1

i have used dispose() , gc.collect(), close() in form2 closing


thanx in advance
harry
 
how important is the use of the memory when form2 is closed, if yer system has plenty of memory to spare then dont worry about it
 
i have studied the memory status of my project
1. Before launching project - 224Mb
2. After launching project - 235Mb
3. Loading Form2 - 254Mb
4. Closing Form2 - 253Mb
5. Application exit - 224Mb

The memory doesn't change drastically to 235Mb After closing Form2
i need to switch over from 254Mb to a range of 235Mb.What do i do
pls suggest some solution
 
You don't need to do anything. A new part of .NET is garbage collection (built in memory management) which is done by the CLR. At certain times (based on specific rules), a task will run through all of our objects looking for those that no longer have any references. Those objects are then terminated; the garbage collected.

This type of memory management has a potential performance benefit; instead of expending the effort to destroy objects as they are dereferenced, with garbage collection this destruction process typically occurs when the application is otherwise idle – often decreasing the impact on the user. However, garbage collection may also occur with the application is active in the case that the system starts running low on resources.

You can manually trigger the garbage collection process using this code:
VB.NET:
System.GC.Collect()
but doing so takes time and is not the sort of thing that should be done each time we want to terminate an object. It's far better to design apps in such a way that it is acceptable for the objects to sit in memory for a time before they are terminated.
 
i'm not clear with your last line

i don't know to design apps in such a way that it is acceptable for the objects to sit in memory for a time before they are terminated.

pls help
 
harvid said:
i'm not clear with your last line

i don't know to design apps in such a way that it is acceptable for the objects to sit in memory for a time before they are terminated.

pls help
it means dont force the garbage collection unless you've got an incredably huge project with thousands of objects and it hits a point where it's waiting for a return on a database querery (through a network) or something that'll take a while to respond.

does that sum it up Paszt?
 
Is there any command in vb.net similar to unload in vb

i have tried close(), dispose(), gc.collect() but memory won't release dratically


pls suggest any solution

regards
harry
 
harvid said:
i have studied the memory status of my project
1. Before launching project - 224Mb
2. After launching project - 235Mb
3. Loading Form2 - 254Mb
4. Closing Form2 - 253Mb
5. Application exit - 224Mb

The memory doesn't change drastically to 235Mb After closing Form2
i need to switch over from 254Mb to a range of 235Mb.What do i do
pls suggest some solution
Try this in your experiment. Launch your app, note the memory, minimize your app, note the memory, restore the app, note your memory.
 
I have already tried that experiment and it works as u said, but it is not actually
my requirement.

As i close the opened form the memory consumption doesn't reduced to the original memory consumption


regards

harry
 
The problem is that you call gc.collect() in Form2's closing event handler. Form2 hasn't been closed yet (it's closing) so the call to collect won't release Form2's resources. It will happen eventially though.

You shouldn't need to call gc.collect(), there's an atricle somewhere that explains why in great detail, but I can't find it right now. Basically the garbage collection algorithms have been very well written and should be able to handle memory management by themselves. I'm not saying you should never call gc.collect, but it should be very rare and under extreme circumstances.
 
hi,

i have seen some solution in the below said url, but this solution suits my problem

http://support.microsoft.com/kb/825680#kb3

My problem states "Virtual Memory Low" but the url info explains about " Out of Memory Exception Errors May Occur When Significant Amounts of Physical Memory Are Still Available "

Does the above said two problems sail in the same boat? Pls i need some guidance. Urgent

Regards
harry
 

Latest posts

Back
Top