inline > -----Original Message----- > From: Discussion of advanced .NET topics. [mailto:ADVANCED- > [EMAIL PROTECTED] On Behalf Of Russell Collins > Sent: 06 September 2007 19:11 > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: Re: [ADVANCED-DOTNET] l immediately release any unneeded > memory > > 1. Every object has a finalizer as well as a constructor in .NET > whether you declare it or not. Most people do not explicitly put > finalizers in so when the Garbage Collector runs, it executes an empty > finalizer. In the normal course of events, when an object is getting > cleaned up, the GC will call the Finalizer. After calling the > finalizer, it will place the object for deletion. By calling suppress > finalize, you skip the finalize step and move to the deletion step.
System.Object has a finalizer but it is ignored by the runtime. The finalizer is only taken any notice of if you override it (dtor syntax in C#) No finalization takes place on an object unless you put override Finalize - take the following code (entered using the Outlook editor ;-) ) class GCMe { } static void Main() { while(true) { new GCMe(); } } You will get about 40 million objects allocated per second and if you look at perfmon virtually no gen1 or gen2 collects occur Now change GCMe to class GCMe { ~GCMe() { } } And the allocation speed drops through the floor (more work is required to allocated an object with a finalizer) and the memory usage goes up as all of those objects are being promoted to gen1 (or even gen2 if you're unlucky) and so are collected less frequently and those collections are more expensive. > > 2. Let me clarify by saying that I did not mean setting a local > VARIABLE > to null. What I meant was cleaning up class level OBJECTS that have > been created by calling the dispose method and/or setting them to Null. > Of course, you are proving my point in that there are a lot of > programmers that are not willing to clean up resources and leave that > to > the Garbage Collector, but it is ALWAYS a good idea and good > programming > practice to clean up resources that you use. Sorry, I wasn't disagreeing with your setting variables to null - just saying that it made no difference at runtime in *most* cases. Regards Richard Blewett - DevelopMentor =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com