|
-
Jul 26th, 2006, 09:22 AM
#1
Thread Starter
PowerPoster
finalize and dispose?
sorry to sound stupid here.
I am wondering what the difference is and what each one does?
Does finalize tell the GC to get the objects to perhaps be disposed of, to be ready in some que?
does dispose get rid of the objects/release the used memory?
-
Jul 26th, 2006, 09:38 AM
#2
Re: finalize and dispose?
Yup.
 Originally Posted by [url=http://msdn2.microsoft.com/en-us/library/system.object.finalize.aspx]System.Object.Finalize()[/url]
The exact time when the finalizer executes during garbage collection is undefined. Resources are not guaranteed to be released at any specific time, unless calling a Close method or a Dispose method.
Finalize is called automatically by the framework. If you need to dump an object you should call its Dispose() method.
-
Jul 26th, 2006, 09:46 AM
#3
Thread Starter
PowerPoster
Re: finalize and dispose?
-
Jul 26th, 2006, 09:48 AM
#4
Re: finalize and dispose?
Also, setting all references to an object to null has no immediate effect, it simply means it will be picked up by the GC on its next run.
-
Jul 26th, 2006, 12:15 PM
#5
Re: finalize and dispose?
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 26th, 2006, 06:09 PM
#6
Re: finalize and dispose?
Finalize, or a destructor in C#, is a fail-safe. It is invoked by the garbage collector to ensure that the Dispose method of an object is executed even if the code that created it did not do so explicitly. If you do not call an object's Dispose method explicitly then it will take multiple passes of the garbage collector to fully clean up that object.
Once no references to an object exist, that object becomes eligible for garbage collection. When the garbage collector feels like it, it will run through the list of all eligible objects. If they have been disposed or have no Dispose method then their memory is reclaimed and they're done. If they have a Dispose method that has not been called then the garbage collector invokes the Finalize method or destructor to dispose the object. They will then have to wait until the next time the garbage collector runs to have their memory reclaimed.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|