Java 中的内存管理 [英] Memory Management in Java

查看:55
本文介绍了Java 中的内存管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Java 中手动删除对象?有没有像 obj.delete()obj.kill()

How can I delete object manually in Java? Is there any method like obj.delete() or obj.kill()

推荐答案

没有真正的方法.Java 有一个特殊的垃圾收集器,可以为您完成这项工作.一旦您的对象没有任何对它的引用,它就会在某个时候被垃圾收集器捡起并销毁.

There is no real way. Java has a special Garbage Collector which does that for you. Once your object doesn't have any references to it, it will be picked up by the Garbage Collector at some point and destroyed.

来自学习 Java 教程:

垃圾收集器

一个对象有资格成为垃圾当没有更多时收集对该对象的引用.参考保存在变量中的是通常在变量变化时下降超出范围.或者,您可以明确地通过设置删除对象引用特殊值的变量空值.请记住,一个程序可以有多次引用同一个目的;对一个对象的所有引用必须在对象被删除之前被删除符合垃圾收集条件.

An object is eligible for garbage collection when there are no more references to that object. References that are held in a variable are usually dropped when the variable goes out of scope. Or, you can explicitly drop an object reference by setting the variable to the special value null. Remember that a program can have multiple references to the same object; all references to an object must be dropped before the object is eligible for garbage collection.

这篇关于Java 中的内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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