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

how to debug web services on consumer side?

580


Define satellite assemblies.

586


What is the difference between “Web.config” and “Machine.Config”?

699


What is view state and how it works in asp net?

555


I have created a configuration setting in my web.config and have kept it at the root level. How do I prevent it from being overridden by another web.config that appears lower in the hierarchy?

546






What is loop in asp.net?

586


What is the difference between web.config and machine.config in ASP.NET?

601


what are configuration files?

565


How will create assesblies at run time?

557


What is application state?

518


Mention few asp.net validators.

580


What is the difference between page directive include and action tag include?

530


What are the file extensions for razor views?

680


Which protocol is used to call a web service?

569


How to rename a table using sql queries?

572