[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 366
  • Last Modified:

Memory Management Question

I have a form that is constantly loading different windows, dialogs, and switching the controls that are in a panel in the mainForm.  It seems that memory is never getting freed for the popup dialogs until I minimize the application then maximize it.  When I have been using it for a while, it takes up about 50 megs.  When I minimize it, it takes up 2, when I maximize it again, it takes up about 12 megs in memory.  As I start to open new Forms and what not, the memory keeps going up again.  Do I need to set them to null after I am done using them?  
0
jjacksn
Asked:
jjacksn
1 Solution
 
ho_alanCommented:
loading forms <-- better to close the unused forms

do u use threading as well? <-- close the unused threads
0
 
TheAvengerCommented:
If you have something like:

NewForm f = new NewForm();
f.ShowWindow (this); // Here some code for the new window takes place

then you don't need to do anything more. The changes in memory size are because of garbage collection and are normal. The garbage collector runs when the memory is over or when the system is idle. Also when you minimize an application, the OS sends a lot of data for this application in the swap (if you have small amount of memory) so it's normal to have only 2 megs in the physical memory and to take more when the application goes visible again.
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  don't rely on task manager for monitoring the used RAM of your app, minimizing the application doesn't mean it's free the memory, it's just remove some parts to the swap file but your application will stay allocate the same amount of ram, for example, look for the performance tab in task manager, and look about the amount of "PF Usage" for example if we say 200mb, when u minimize your application the process tab will tell you your application used much less Ram, but if you look at the performance again you will see the same Ram used (200mb) and not decreased, because the process tab show only the amount of your application used in the phsyical Ram not all the Ram it's allocate, which will be in Phsyical Ram and in swap file

to debug memory leaks in your application look about AQtime .NET
http://www.automatedqa.com/products/aqnet.asp
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
AgariciCommented:
if you want to free some memory, you may call the Collect method of the garbage collector more frequently then gc usuallly calls it (when you destroy an object it is only marked for deletion - it will actually be removed from memory when the heap is full; however you can force garbage collection by calling the Collect method )
see the documentation for garbage collector
0
 
SijinCommented:
Are you closing the forms or just hiding them?...

You should use Form.Close() to close the form. If you are just creating new forms and not closing the previous ones your memory usage will grow as the application runs. Hard to day the excat cause without some code.
0
 
EBatistaCommented:
jjacksn,  in this room we had seen a lot of questions like this (me included) about memory leaks and huge memory allocated in the manage heap in .NET, here is the history of one of them:
 
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20686781.html

hope this help you to stay cool

EB
0
 
andyalmqCommented:
I think the best answer to your question is that this is normal with .Net.  The .Net garbage only frees memory at certain times.  This is why you notice that your application takes up more and more memory as it runs.    This page explains how garbage collection is handled in .Net: http://msdn.microsoft.com/msdnmag/issues/1100/GCI/default.aspx

If you really want to, you can cause garbage collection to happen at any point, although this is not normally reccomended as it can negatively effect your application.  In most cases, though, it's best to let .Net collect the memory itself.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now