raj kumar
Difference between Dispose and Finalize method ?
By raj kumar in ASP.NET on Nov 07 2007
  • Umar Ali
    Sep, 2012 1

    Please refer to the following URL to know the differences between Dispose() and Finalize() methods,http://onlydifferencefaqs.blogspot.in/2012/08/dotnet-framework-difference-faqs-2.html

    • 0
  • Elias  Hossain
    Feb, 2008 23

    Finalize:- .NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources ( ex: Windows API created objects, File, Database connection objects, COM objects etc) is outside the scope of .NET framework we have to explicitly clean our resources. For these types of objects .NET framework provides Objects. Finalize method which can be overridden and clean up code for unmanaged resources can be put in this section.
    Dispose:- Dispose method belongs to IDisposable interface. If you want to release unmanaged objects then it is the best to implement IDisposable and override the Dispose method of IDisposable interface. Now once your class has exposed the Dispose method it's the responsibility of the client to call the Dispose method to do the cleanup.

    More important .NET Questions And Answers

    • 0
  • Elias  Hossain
    Feb, 2008 23

    Finalize:- .NET Garbage collector does almost all clean up activity for your objects. But unmanaged resources ( ex: Windows API created objects, File, Database connection objects, COM objects etc) is outside the scope of .NET framework we have to explicitly clean our resources. For these types of objects .NET framework provides Objects. Finalize method which can be overridden and clean up code for unmanaged resources can be put in this section.
    Dispose:- Dispose method belongs to IDisposable interface. If you want to release unmanaged objects then it is the best to implement IDisposable and override the Dispose method of IDisposable interface. Now once your class has exposed the Dispose method it's the responsibility of the client to call the Dispose method to do the cleanup

    • 0
  • Muralidhar A
    Nov, 2007 7

    Finalie() method will be called by the runtime. i.e, Garbage collector will take the responsiblity to deallocate the memory for the specific object. But the problem is we can not assume when it will be deallocated. For that, .NET framework supports Dispose(), by using this when ever you think, the object no longer needed, as soon as possible you have to specify objname.dispose(). in u r code.

    One more question may be raised in this topic, how to destroy the object of com component in u r .NET application. because CLR does not take the  responsiblity to deallocate the objects for unmanaged code. To do this,

    System.Runtime.InteropServices namespace provides one class named  Marshal.ReleaseComObject(object name)

    By using this we can deallocate the memory for com componet in .NEt application.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS