请问怎么在java中实现 类似于 c++中 destructor 函数的功能。

eagle19790214 2003-09-25 02:36:22
:),谢谢
...全文
62 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ppgoodboy 2003-09-26
  • 打赏
  • 举报
回复
通常情况下,不用finalize()方法,java有自带的垃圾回收机制garbage collector,也就是gc().
有空的时候可以看看http://java.sun.com/docs/books/tutorial/对学习java很有帮助。
jiganghao 2003-09-26
  • 打赏
  • 举报
回复
java.lang.Object has a finalize() method. It is similar to desctrutor in C++, but there are important differences.

finalize() is basically for release non-memory resources that the object holds reference to, like database connection, file handle, etc. In java, memory allocation/release is not an issue.

But there is no deterministic time when finalize() is called. It depends on garbage collector behavior. So you'd better don't use it.

refer the book 'effective java', itme 6 'avoid finalizers'. Hope there is a chinese version available.

51,407

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧