JVM example getObjectSize

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.

Can someone help me?

+5
source share
4 answers

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 ...

+9

, , Jamm, JVM.

+1

MemoryMeasurer library, API. ( , , , .)

0

All Articles