Solved

Memory Management Question

Posted on 2003-11-10
7
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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