I have some problems getting the size of an object in the JVM. JDK 5 offers an interface Instrumentationfor calculating through a function premain(), but I don't know how to use it.
Instrumentation
premain()
Can someone help me?
the easiest and most efficient solution is to use a very small sizeof library
<dependency> <groupId>com.carrotsearch</groupId> <artifactId>java-sizeof</artifactId> <version>0.0.3</version> </dependency>
you need to use http://grepcode.com/file/repo1.maven.org/maven2/com.carrotsearch/java-sizeof/0.0.2/com/carrotsearch/sizeof/RamUsageEstimator.java?av=f
shallowSizeOf () or sizeOf () method
This is really the easiest quick fix I've found on this topic so far ...
, , Jamm, JVM.
Dustin Marx, .
http://java.dzone.com/articles/estimating-java-object-sizes
MemoryMeasurer library, API. ( , , , .)