Calculate memory usage of Java objects

With Twitter’s ObjectSizeCalculator

If you are looking for an easy way to estimate the object size than this could interest you.


// gradle dependency
// https://mvnrepository.com/artifact/com.twitter.common/objectsize 
compile group: 'com.twitter.common', name: 'objectsize', version: '0.0.12'

System.out.println(
  ObjectSizeCalculator.getObjectSize(myObject)
);

The memory size of your object depends on the architecture, the actual vm implementation and whether the VM is 32 or 64-bit. ObjectSizeCalculator supports only the Hotspot JVM.

For more information see the javadoc ObjectSizeCalculator.

Links
https://twitter.github.io/commons/

https://stackoverflow.com/questions/9368764/calculate-size-of-object-in-java

https://dzone.com/articles/java-how-to-calculate-size-of-objects-amp-arrays-b