Solved

Memory Management Question

Posted on 2003-11-10
7
352 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:
Mohammed Nasman 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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…

867 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

19 Experts available now in Live!

Get 1:1 Help Now