For statistics reporting purposes of an application, I want to measure periodically, how much memory (in bytes) an object consumes. I am aware that unlike C/C++, Java does not have a built-in sizeOf() method, but it can be achieved through Java Instrumentation.
However for the application I am developing, there are some constraints;
- Should not use Java Instrumentation (since the client does not want to have a pre-main and an external agent).
- Memory measuring algorithm itself should not be memory/time consuming.
- A qualitative measurement is acceptable, but it should consider the deep-size of an object.
I went through answers for question "In Java, what is the best way to determine the size of an object?" and even accepted answer suggest Java Instrumentation. Since it is not acceptable in this scenario, I went with Dimitris Andreou's ObjectExplorer, which uses a reflection-based object-traversing framework to produce a qualitative measurement. However, that consumes a considerable amount of time and memory when it comes to measuring objects that are around 80MB (deep-size). So my question is is there another way to achieve this, with above constraints?