Java VisualVM memory sampler - how to get the size of a specific class

My application uses a lot more memory than I think, it is assumed that it will be used, and I'm trying to figure out which class uses a lot of memory and may not release it.

I use VisualVM, and in the memory sampler I see that most of the memory is spent on Chars, Strings and Bytes, all my classes use Strings, but as you know, VisualVM shows ALL Chars and Strings in the system (all characters are identical to the strings, which makes it difficult to understand who is holding them), as I understand it, the size of other classes that contain these strings is calculated without strings.

How can I see in this tool that the “real” biggest classes are the ones that contain all these lines? (preferably if I get from these classes to their lines, and not vice versa) I tried to use the "root in the nearest GC" in heapDump, but there are about 4,000,000 lines, so the likelihood that I find "problematic" is very small ...

Thanks!!!

+6
source share
2 answers

If you make a bunch of heaps, you can find the 20 largest objects (including all the space that it refers to). For anything else, I recommend using the very handy OQL console.

Basically you are looking for the following:

Lot of String taking up 20Mb --- kept alive by ---> HashSet#28839 --- kept alive by ---> MyOwnClass#88293 

I suggest you take a random string, find it as a link, and analyze it until you find out about a possible suspect. Once you have this suspect, you can run an OQL query using http://visualvm.java.net/oqlhelp.html#rsizeof to find out the total size of these objects.

+2
source

Create a heap heap, open its MAT and look in the histogram for the largest saved sizes.

+2
source

Source: https://habr.com/ru/post/905518/


All Articles