473,800 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1515
"Sput" <sp********@pos t.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/
"Programmin g 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********@pos t.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/
"Programmin g is an art form that fights back"
ELKNews - Get your free copy at http://www.atozedsoftware.com

Nov 15 '05 #3
"Sput" <sp********@pos t.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.Colle ct();
System.GC.WaitF orPendingFinali zers();

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.co m

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

"Chad Z. Hower aka Kudzu" <cp**@hower.org > wrote in message
news:Xn******** **********@127. 0.0.1...
"Sput" <sp********@pos t.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/
"Programmin g 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
1370
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. Can I achieve this in .NET ?
28
3391
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 images that have been used and are going to be closed. This is how ever no way to reduce the memory consumption. I have noticed , using the task manager, that garbage collector doesn't actually do any collections unless the computer becomes low...
10
2055
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
12955
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 that the object will not be garbage collected while the thread is running. Fair enough, the documented explanation is that the GC compresses objects on the heap and needs to update references, the references will be invalid for a couple of moments...
8
3048
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 the mainline. The class that instantiated the object in question is definitely still in existence at the point garbage collection swoops in and yanks it out from under my processing. Is there a way to ensure an instantiated object cannot be freed...
56
3719
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 = null; Private Microsoft.Office.Interop.Outlook.NameSpace _Namespace = null; The Constructor: public OutlookObject()
46
2194
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, and auto_ptrs, gurus suggest that may be better to use a reference-counted smart pointer, or a garbage-collector. But in which cases it is better to use one technique and in which cases another? IOW, which is the design criterion?
11
1772
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 coordinates. I'm going to try an STL Map or Multiset. Maybe that works faster and more memory efficient. I have never heard before of a pool allocator but will Google for it.
158
7912
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 discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
9690
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

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.