I did some benchmarks comparing performance of int vs Integer, long vs Long, empty class instance vs class instance with long value.
And I have few questions which I cannot answer myself:
- why instantiating of empty class or object takes 28 bytes?
- instantiating of Long object takes 29 bytes, primitive long 8 bytes, so why the difference to empty class is only 1 byte? what kind of optimization is JVM doing?
I used JDK1.6.0_30 on MacOS, and the code is available at
https://github.com/mousator/benchmarks/blob/master/src/sk/emandem/michal/AutoboxingTypeBenchmark.java
(you can checkout the whole project)
Thanks for answers!
runtime.gc()doesn’t necessarily do anything. Use a tool like MemoryMeasurer.