When we have a reference variable e.g. to simplify it Integer i
we can assume that the size of i
is approximately 16 bytes overhead + 4 bytes for the actual int + 4 bytes padding i.e. 24 bytes.
So my question is if i
is null do we only have 4 bytes of the reference not pointing anywhere or is there any other extra "hidden" information adding to this?
If I recall correctly, the JVM specification mentions that null
is not required to have a specific value or representation, so it could be anything. What it typically is, I don't know, but a fair guess is probably 32 or 64 bits of zeros, depending on the JVM version.
Edit: Here's the relevant section: http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.4
The Java Virtual Machine specification does not mandate a concrete value encoding null.
Cheers,
Yeah it still uses memory. Uses 4 bytes for a 32bit and 8 for a 64 I believe.
found more information on this: Java - Does null variable require space in memory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With