I have some trouble on getting the size of an object in JVM. JDK 5 offer an interface Instrumentation
to calculate through premain()
function, but I do not know how to use it.
Can anybody help me?
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...
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