为什么对象具有在.NET中具有终结器的死亡 - 活死(复活) [英] Why object have death-alive-death (resurrected) that have finalizer in .NET

查看:96
本文介绍了为什么对象具有在.NET中具有终结器的死亡 - 活死(复活)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



为什么Garbage-Collection为在.net中有终结器的对象提供更多生命。



谢谢

Dinesh

解决方案

有趣的问题。复活在这里解释: http://msdn.microsoft.com/en-us/magazine/bb985010.aspx [ ^ ]。



这篇微软文章的质量有点质疑:它指的是.NET中不存在的全局对象的概念(所以你可以考虑它)正如不准确的措辞一样,没有讨论参考死者对象的可达性,并且没有清楚地概述复活的目的。



你可以考虑GC架构的这一特性(复活行为,以及 GC.ReRegisterForFinaliz )作为一种措施来涵盖用户代码的一些理论上可能的病态案例与使用方法 Finalize 有关,当它的代码保存对这个的引用时(并不一定是某些stati) c成员,如本文所述;它可能是某个静态对象的某些非静态成员,依此类推,任何本身都有root的东西。在实践中,我认为最好避免这种最终化行为。如果有人根据复活行为发明真正有用的技术,我会感到惊讶。即使有一些使用它,我会质疑它是否可以被认为是实用的。



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



-SA

Hi Experts,

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

Thanks
Dinesh

解决方案

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


这篇关于为什么对象具有在.NET中具有终结器的死亡 - 活死(复活)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆