Solved

Memory Management Question

Posted on 2003-11-10
7
351 Views
Last Modified: 2013-12-03
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
Comment
Question by:jjacksn
7 Comments
 
LVL 5

Expert Comment

by:ho_alan
ID: 9720596
loading forms <-- better to close the unused forms

do u use threading as well? <-- close the unused threads
0
 
LVL 20

Expert Comment

by:TheAvenger
ID: 9720765
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
 
LVL 22

Accepted Solution

by:
mnasman earned 250 total points
ID: 9721272
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 11

Expert Comment

by:Agarici
ID: 9721282
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
 
LVL 3

Expert Comment

by:Sijin
ID: 9721569
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
 
LVL 10

Expert Comment

by:EBatista
ID: 9725239
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
 
LVL 1

Expert Comment

by:andyalmq
ID: 9750626
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now