JVM getObjectSize example
the simplest and the most efficient solution is to use very small sizeof library
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>java-sizeof</artifactId>
<version>0.0.3</version>
</dependency>
you need to use this http://grepcode.com/file/repo1.maven.org/maven2/com.carrotsearch/java-sizeof/0.0.2/com/carrotsearch/sizeof/RamUsageEstimator.java?av=f
shallowSizeOf() method or sizeOf()
That's really the simplest working fast solution i found on this topic so far...