你如何用Java编写解构函数? [英] How do you write a deconstructor in Java?

查看:729
本文介绍了你如何用Java编写解构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个问题并且正在寻找一些想法?

I came across this question and am looking for some ideas?

推荐答案

您不需要(也不应该尝试使用)析构函数 - 或者在Java中调用它们:终结器 。

You do not need (nor should you try to use) destructors - or what they are called in Java: "Finalizers".

VM规范允许VM实现永远不会调用它们。因此,它们对资源发布等不可靠。一般来说,在对象被垃圾回收之前,VM可以调用任何对象的 finalize()方法中的代码,但由于这不是强制性的,所以应该避免使用它。

The VM specification does allow for VM implementations to never call them. So they are not reliable for resource releases and the like. Generally speaking the code in the finalize() method of any object can be called by the VM before the object is garbage collected, but as this is not mandatory, you should avoid it.

这篇关于你如何用Java编写解构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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