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
We Only Know The Total Number Of Feet In The Farmyard. Write A Program that will compute the total number of rabbits and chickens in the farmyard. Assume number of feet in the farmyard are 40. how many rabbits and chickens are?
Differentiate between globalization and localization.
How can we communicate with each server in N-tier Architecture? and what are the methods?
What is _viewstart?
What is the difference between file-based dependency and key-based dependency?
How can you dynamically add user controls to a page?
Hi All, Im an MCA holder with 3+ years of experience in asp.net. Now i want to move to some good government job. I have no idea about different categories of exams held & which one can be applicable for my education background. I have done B.A with MCA. Please help me out with your valuable suggestions. I would be very grateful. Thanks Anuj
What are sessions used for?
What is server infrastructure?
What is the difference between ldap and active directory?
What is voluum?
How can we add an event handler for a ASP.NET function executed on MouseOver for a certain button.
Define repository pattern in mvc.net? : asp.net mvc
Explain managed code an un-managed code.
How can i explain my project during interview?many time i expalain my project but they did't accept? please explain me.