Ruby 如何检测 runtime 中一个 instance 存在时间

anklos · April 18, 2012 · Last by anklos replied at April 23, 2012 · 2674 hits

只能程序里自己打表计算吗?

就算有内置工具或者方法什么的 也是打表 没区别

@bony 恩,只是想方便调用。不过我发现这个不能在 constructor 和 destructor 里实现,因为: #Objects are destroyed by the garbage collector. #The time of destroying is not predictable.

其实有 gc 机制的你很难去计算 因为回收不是你说的算。而且这种计算也是虚拟机来完成。你可以读 ruby 源码看看回收机制。

@anklosBasicObject#initializeObjectSpace.define_finalizer哈 自己给 object 添个方法不就得了

@camel 是的没错,多谢多谢!

You need to Sign in before reply, if you don't have an account, please Sign up first.