I know an object reference or object handle has a size itself and the size is JVM dependent. I am just wondering what will happen after it has been explicitly set to null. Say we have a variable Object o = new Object() and later we set o = null. Will it be garbage collected?
I know an object reference or object handle has a size itself and the
Share
In your example:
Assume
ois either a field or a local variable/parameter. In the former situation it occupies 4/8 bytes in some other (outer) object. These bytes will be garbage collected when outer object is garbage collected.If
ois a parameter/local variable, no garbage collection is needed, the JVM will “recycle” the stack and simply reuse/erase that space.