Click here to Skip to main content
15,908,445 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what is the difference between finalize and finalizer in .net ?
Is there any difference in finalize and finalizer?
What is finalizer?
Posted

The Finalize method[^] is used to allow you to "clean up" after yourself and release any resources your class instance has created.

A Finalizer[^] is just the generic term for such methods.
 
Share this answer
 
Finalizer is destructor of the class. Finalize is the method called by the garbage collector. I think I remember Finalize is implicitly called by the destructor, but I didn't check if I remember correctly right now :)

Similar, but not same is Dispose method that is used by objects implementing IDisposable. Good practice says you should call Dispose on the object implementing IDisposable. You should NEVER call Finalize directly (or destructor for that matter).

You can force garbage collection with GC.Collect(), but this can have performance issues and is not recommended. Call Dispose where needed and let GC do its magic.
 
Share this answer
 
Comments
Rahul Kumar 11-Mar-15 4:58am    
So can we say both finalizer and finalize same.Garbage collector uses which word finalizer or finalize .
Sinisa Hajnal 11-Mar-15 7:44am    
They do the same (mostly) work, but are not the same. Destructor (finalizer) calls Finalize, but also destroy object and probably does some other things. Finalize is a method you can (but shouldn't) call. GC calls the destructor that calls Finalize.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900