What is the Difference B/W Finalize() and Dispose() in .Net?
Answer Posted / karna
when we write the destructor in c#,the runtime replaces the
destructor with the finalize method in IL code,so we dont
know at what time the destructor is called by the garbage
collector.so the finalizer is non deterministic.if we want
to do the garbage collection for unmanages resources,we
have to implement our own destructor or finlizer
method.but,the runtime will take two round trips to remove
those objects from the heap.if runtime calls the own
destructor,it will take onely one round trip.
to remove the unmanaged resources without the performance
issues,we have to inherit the System.Idisposable interface
and implement the Dispose() method.here one problem is
there,we have to write a code in a way that,the dsipose
method must and should execute.
for that reason we have to keep the dispose methos for the
objcets in the finally block.
problem with the dispose is that,some times because of
some problmes dispose() methos may not execute.
so the good practice is to use both to achieve the desied
performance.
| Is This Answer Correct ? | 20 Yes | 3 No |
Post New Answer View All Answers
What does uri mean?
What are the new features added from ASP to ASP.NET?
What is the difference between file-based dependency and key-based dependency?
Is it right that ASP.NET Web API has replaced WCF?
What is the use of global.asax file?
Explain the difference between web user control and web custom control?
What is difference between asp.net and asp.net mvc? : Asp.Net MVC
Explain the concept of MVC Scaffolding?
Why we use dbms for projects? Why don’t we save any application data in separate files instead of dbms?
How to set the pane area to transparent of a scrollPane component.?
What is asp.net introduction?
What is server infrastructure?
calling result set one procedure to anothar procedure in sql2000
Can we have multiple web config files for an asp.net application?
What are the built-in objects in asp.net?