It is important to understand that the destructor is called just prior to garbage collection.It is not called when a variable containing a reference to an object goes out of scope, for example. (This differs from destructors in C++, which are called when an object goes out of scope.) This means that you cannot know precisely when a destructor will be executed. Furthermore, it is possible for your program to end before garbage collection occurs, so a destructor might not get called at all.
转载于:https://blog.51cto.com/cnn237111/467666
本文探讨了析构函数在程序中的调用时机,尤其是在垃圾回收机制中的作用。不同于C++中对象生命周期结束时调用析构函数的方式,在某些语言中,析构函数的执行依赖于垃圾回收过程,这意味着无法精确预测其执行时间,并且如果程序提前结束,析构函数可能不会被调用。
2133

被折叠的 条评论
为什么被折叠?



