What is the Difference B/W Finalize() and Dispose() in .Net?

Answer Posted / sreeram pavan

Both are ways to destroy the object. By object i mean when
you have some unmanaged resources used in your class, you
have to make sure that you write the logic to destroy them
in the finalize() method. But this is the implicit way of
destroying the unmanaged resources, as finalize is called by
garbage collector when it find thats there is no reference
to this object from the stack.
There is an explicit way to destroy the unmanaged resources.
That is by implementing IDisposable interface. By
implementing this interface, ie you have to write the code
to destroy the resource in Dispose() method, you can call
the object to destroy itself when ever required in your code.

Is This Answer Correct ?    51 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

in which protocol ASP.NET WEB API Work?

619


How can you dynamically add user controls to a page?

519


Explain diff. Between friend and protected friend?

506


What is a postback in asp net?

542


How will you load dynamic assembly?

547






Is it possible to migrate visual interdev design-time controls to asp.net?

571


How ASP and ASP.NET page works? Explain about asp.net page life cycle?

593


What do you mean by query string?

524


What is datagrid asp.net?

501


Can you explain autopostback?

541


Is post back property in asp net?

531


What is difference between asp.net and asp?

569


What r the asp.net list controls and diff. Between them?

510


Why would a company use an application service provider?

496


How to unit test Web API?

714