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

Answer Posted / purushottam kumar, mcad, mcsd

Finalize :
1.Finalize() is called by the runtime
2.Is a destructor, called by Garbage Collector when the
object goes out of scope.
3.Implement it when you have unmanaged resources in your
code, and want to make sure that these resources are freed
when the Garbage collection happens.

Dispose :
1.Dispose() is called by the user
2.Same purpose as finalize, to free unmanaged resources.
However, implement this when you are writing a custom class,
that will be used by other users.
3.Overriding Dispose() provides a way for the user code to
free the unmanaged objects in your custom class.

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain in what order a destructors is called.

575


Explain asp.net application life cycle?

537


What is the use of data set in asp.net?

478


Describe how ASP.NET maintains process isolation for each Web application?

565


What is application variable in asp.net?

461






What are Session states available and its Uses?

1687


Name the method that needs to be invoked on the dataadapter control to fill the generated dataset with data?

531


Describe the differences between the lifecycles of Windows services and Standard EXE?

594


What is the behavior of a Web browser when it receives an invalid element?

616


What is difference between abstract class and an interface?

495


how to include timer or counting time to display next page in asp.net

1592


What is the difference between union and structure?

497


What is x xss protection?

556


Explain the difference between overriding and overloading?

532


Explain the difference between singleton and single call?

527