Solved

Memory Management Question

Posted on 2003-11-10
7
355 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

777 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