如何在 Java 中手动删除对象?有没有像obj.delete()
这样的方法或obj.kill()
最佳答案
没有真正的办法。 Java 有一个特殊的垃圾收集器来为你做这件事。一旦你的对象没有任何引用,它就会被垃圾收集器在某个时刻拾取并销毁。
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/