473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

garbage col. vs manual cleaning

I have a program with many forms which users are often opening and closing.

Now, I have noticed that after opening 10 different forms and the closing
them, memory consumption increases (eg. it has 25mb before opening 10 forms,
then while they are open it has 26mb, after closing it has 25.8mb)

After user is working for several hours, mem. usage jumpes to 70-100mb.

Should I manually clean up after form closes or does the garbage collector
clean everything?
(ie there is a lot of graphics loaded from outside on forms and maybe gc
does not dispose of them - entirely?)

Nov 15 '05 #1
4 1501
"Sput" <sp********@post.htnet.hr> wrote in
news:bu**********@ls219.htnet.hr:
Should I manually clean up after form closes or does the garbage
collector clean everything?
(ie there is a lot of graphics loaded from outside on forms and maybe gc
does not dispose of them - entirely?)


There is no way to manaully clean up. Just make sure all your references are
set to null, or are dereferenced. The GC will take care of the rest.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 15 '05 #2

"Chad Z. Hower aka Kudzu" <cp**@hower.org> wrote in message
news:Xn******************@127.0.0.1...
"Sput" <sp********@post.htnet.hr> wrote in
news:bu**********@ls219.htnet.hr:
Should I manually clean up after form closes or does the garbage
collector clean everything?
(ie there is a lot of graphics loaded from outside on forms and maybe gc
does not dispose of them - entirely?)
There is no way to manaully clean up. Just make sure all your references

are set to null, or are dereferenced. The GC will take care of the rest. Well, depending on what you are using, you really should be calling Dispose
on objects like Graphics and Image, that likely isn't the cause of the
memory issue however. You need to make sure you aren't maintaining
references to objects you no longer need(probably Image or Graphics
classes), a memory profiler will help here.

--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 15 '05 #3
"Sput" <sp********@post.htnet.hr> wrote in message news:<bu**********@ls219.htnet.hr>...
I have a program with many forms which users are often opening and closing.

Now, I have noticed that after opening 10 different forms and the closing
them, memory consumption increases (eg. it has 25mb before opening 10 forms,
then while they are open it has 26mb, after closing it has 25.8mb)

After user is working for several hours, mem. usage jumpes to 70-100mb.

Should I manually clean up after form closes or does the garbage collector
clean everything?
(ie there is a lot of graphics loaded from outside on forms and maybe gc
does not dispose of them - entirely?)


Garbage collector won't collect memory till it doesn't feel the need
of it. Internally, how that feel is decided, We don't know. If you
have lot's of ram and few programs running, it may not tend to free up
resources.

Few points:

- Just check if you are using destructurs in your forms or classes
Internally they get converted to Finalize method, and such classes
gets promoted to longer generation, remaining in memory for more time.
If it is so, try overriding Dispose method also, and call it when you
are done with resources.

- You can manually call GC.
As you are working with manual interaction, you must have plenty of
time, when much is not being done and you call GC as static method
System.GC.Collect();
System.GC.WaitForPendingFinalizers();

Have a nice day
Manish Singh
Nov 15 '05 #4
Daniel, Chad and Sput,

When closing the form, you should be calling Dispose on the Form. This
should call dispose on the Form, and any control references it contains.
While you might not see a difference in the memory consumption (because the
object representation still might be around in .NET), you will properly
dispose of window handles that are no longer being used.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...

"Chad Z. Hower aka Kudzu" <cp**@hower.org> wrote in message
news:Xn******************@127.0.0.1...
"Sput" <sp********@post.htnet.hr> wrote in
news:bu**********@ls219.htnet.hr:
Should I manually clean up after form closes or does the garbage
collector clean everything?
(ie there is a lot of graphics loaded from outside on forms and maybe gc does not dispose of them - entirely?)
There is no way to manaully clean up. Just make sure all your references

are
set to null, or are dereferenced. The GC will take care of the rest.

Well, depending on what you are using, you really should be calling

Dispose on objects like Graphics and Image, that likely isn't the cause of the
memory issue however. You need to make sure you aren't maintaining
references to objects you no longer need(probably Image or Graphics
classes), a memory profiler will help here.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com


Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Rimonne | last post by:
Hi All I understand that the .net framework has garbagecollectors which run automatically and release memory. But in my application in C#, i have an object which should never be released. ...
28
by: joe | last post by:
I have a simple .NET application with two or three listViews which are filled with icons and when the user click on the proper item, they display the related images. I use "image = null ; " for all...
10
by: pachanga | last post by:
The Hans-Boehm garbage collector can be successfully used with C and C++, but not yet a standard for C++.. Is there talks about Garbage Collector to become in the C++ standard?
8
by: Martin Maat | last post by:
I am puzzled. I have this object that uses a thread. The thread is encapsulated by the object, the object has Start and Stop methods to enable the client to start or stop the thread. I found...
8
by: mike2036 | last post by:
For some reason it appears that garbage collection is releasing an object that I'm still using. The object is declared in a module and instantiated within a class that is in turn instantiated by...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
46
by: Carlo Milanesi | last post by:
Hello, traditionally, in C++, dynamically allocated memory has been managed explicitly by calling "delete" in the application code. Now, in addition to the standard library strings, containers,...
11
by: brey_maastricht | last post by:
Thank you all for your replys ! Indeed I am using a vector<vector<nDimensionalPoint * as Hashtable. My requirement is to lookup the value of a point of n dimensions very fast for given...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.