Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi Experts,

Why Garbage-Collection give one more life to object that have finalizer in .net.

Thanks
Dinesh
Posted
Comments
Sergey Alexandrovich Kryukov 6-May-14 1:01am    
Interesting advanced question. I voted 5 for it.
—SA

1 solution

Interesting question. Resurrection is explained here: http://msdn.microsoft.com/en-us/magazine/bb985010.aspx[^].

The quality of this Microsoft article is just a bit questionable: it refers to the concept of "global object" which does not exist in .NET (so you can consider it just as inaccurate wording), the reachability of the holder of the reference to the dead object is not discussed, and the purpose of resurrection is not clearly outlined.

You can consider this feature of GC architecture (resurrection behavior, as well as GC.ReRegisterForFinaliz) as a measure to cover some theoretically possible pathological cases of user code related to the use of the method Finalize, when its code saves the reference to this (and not necessarily to some static member as explained in this article; it could be some non-static member of some static object, and so on, anything which itself has a root). In practice, I think such behavior of finalization is best avoided. I would be surprised if someone invents really useful technique based on resurrection behavior. And even of there is some use of it, I would question if it can be considered practical.

See also: http://blogs.msdn.com/b/abhinaba/archive/2009/04/13/object-resurrection-using-gc-reregisterforfinalize.aspx[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900