0

I'm running Java Visual VM to analyze performance on a Mule app to reduce the amount of memory used. When I look at the heap dump, I see that char[] has a size of over 37 MB, String has a size of a bit over 28 MB.

What I'm not clear on is how the size column accounts for the amount of memory used. In particular, since a String is an abstraction of a char[], I'm wondering if this means that some of that 37 MB of char arrays is also present within the 28 MB of Strings, or if they are allocated separately.

On top of that, I also have a class that I suspect is hogging a great deal of memory and contains several strings, but according to my heap dump, this class only uses 6.5% of the total memory in the heap.

So I guess my question is... If I were to make my custom class more efficient by using fewer String objects, would I see a reduction in the amount of memory reported to be used by Strings and Char[]s, or just for that specific class?

Thanks!

Drew Ingram
  • 75
  • 1
  • 9
  • The sizes only include the memory for an object itself, not any referenced object (and arrays are objects). What you are looking for, is "retained size"; VisualVM has options for showing it, but its calculation may take some time, as it has to find out whether there are other references to the same object. – Holger Feb 07 '19 at 22:03
  • Thanks pretty much all I needed to know. Thanks! – Drew Ingram Feb 08 '19 at 23:36
  • IIRC `jol` can also get the size of some object (deep size) – Eugene Feb 10 '19 at 04:22

1 Answers1

0

Holger's comment is all I needed...

"The sizes only include the memory for an object itself, not any referenced object (and arrays are objects)."

This alone gives me a much better idea of how I can optimize.

Drew Ingram
  • 75
  • 1
  • 9
  • These values give a good hint for optimizations, when using them for comparison or looking at the biggest chunks to identify the levers to the memory consumption. But it's worth knowing https://shipilev.net/blog/2014/heapdump-is-a-lie/ to take the values with a grain of salt. – Holger Feb 09 '19 at 09:30
  • @Holger what I *love* about shipilev, that he does not only say - "hey, there is a problem here", but also tries to solve it. That is a very famous article if his, but he also created `jol` – Eugene Feb 10 '19 at 04:24