java - Java 中的内存管理

标签 java memory-management

如何在 Java 中手动删除对象?有没有像obj.delete()这样的方法或obj.kill()

最佳答案

没有真正的办法。 Java 有一个特殊的垃圾收集器来为你做这件事。一旦你的对象没有任何引用,它就会被垃圾收集器在某个时刻拾取并销毁。

来自Learning Java Tutorials :

The Garbage Collector

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 - Java 中的内存管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6466353/

相关文章:

java - 将 ISO8601 日期时间转换为另一种基于 Java 中的州名称的 ISO8601 格式?

python - 将 numpy 数组设置为 None 是否释放内存?

java - 如何在Java程序中通过命令提示符运行.exe文件?

java - Android:无法从扩展Thread的类中调用新 Activity

java - Set<CharSequence> 和 Map<CharSequence, Object> 从 CharSequence 更改为 String

ios - 使用MonoTouch和MonoTouch.Dialog进行内存/资源管理

c - 为什么c语言中没有检查数组使用的下标是否超过数组的大小?

java - 通用类型类型的行为不符合预期

javascript - JS 是否总是每个字符使用两个字节来存储字符串?

javascript - 我应该取消绑定(bind)事件监听器以防止内存泄漏吗?