-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have a way to (estimate) the size of an object? #337
Comments
size in matter of number of elements (OK), or size in matter of bytes (depends on JVM, may not change if a field is removed or added due to memory alignment)? |
e.g JProfile and also other tools can show such information without taking a heap dump so the JVM seem to expose such data somehow to special agents and I supose a debugger is such special thing.
Usually my JVM does not change while I'm in a debugger session |
yea, but such numbers are typically guesses or at least not generally valid and may be misleading. |
I don't need exact numbers, but it is important to "see" if my object is about 1 MB 10 MB or 100MB and if I change something it is maybe half that size (estimate). I also don't need to compare numbers across different JVMs or different computers. |
I believe I've seen recently code in JDT tests that did estimation of object size. Sorry can't remember where it was. |
please have a look at https://docs.oracle.com/en/java/javase/17/docs/api/java.instrument/java/lang/instrument/Instrumentation.html
It has a method getObjectSize(...)
|
What I'm currently missing when analyze memory problem is that I can see in a heapdump how much size an object has allocated, but later on in the debugger when analyze the problem one is a bit "blind".
It would be great if it would be possible to select a variable in the debug view and ask for the (direct and retained) size e.g. of a Map/List/....
The text was updated successfully, but these errors were encountered: