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

Why we use dbms for projects? Why don’t we save any application data in separate files instead of dbms?

548


What are triggers of an updatepanel?

548


About CLR, reflection and assemblies?

1533


Where can I get information on cookies in asp.net?

560


What is a 404 redirect?

548






What is meant by ispostback in asp net?

535


Explain the main function of razor in asp.net? : asp.net mvc

579


What does a switch do?

529


Explain about consistent programming model in the .NET framework?

585


Explain the asp.net mvc request life cycle? : asp.net mvc

493


3. What goals do you have in your career?

1414


Explain about asp.net 2.0 themes?

549


How can we inherit a static variable?

535


What is the significance of attaching a profile while creating a user?

559


How to improve performance of web application asp.net mvc? : Asp.Net MVC

485