0

I'm analyzing the memory usage of my program, and I realized it was using 50 mb of memory... what could it possibly need all that for? (the program is fairly simple, it's not hello world but it's only 937 non whitespace lines). So I put it into jhat, and I get a lot of information that has no indication of references for all these Integer, Character and Byte arrays.

Here's the image that shows the biggest memory hogs:

Overall memory usage

When you click on class[I, there's a lot of stuff that looks like:

Unknown reference array examples

Of the almost 5000 instance counts, most of the memory usage is in the largest 22 arrays (I figured that out using excel), of which 15 have size 2677104. And they seem to be arrays of almost entirely zeroes, as seen here:

Example large array

Reference chains from rootset gives nothing. Clicking on "Objects reachable from here" doesn't give anything useful, I think:

enter image description here

What is using this memory? I am using the following libraries: netty 3.6.5, mbassador 1.1.7, guice 3.0, guava 14.0.1, logback 1.0.11, joda-time 2.1, gson 2.2.3.

Update: I ran the exact same heap dump into Eclipse MAT and got different results...

MAT dump

I wonder if those large arrays were scheduled for GC and MAT is filtering them out? Perhaps I'm analyzing my program too soon... "about 97% of the time: premature optimization is the root of all evil" - Donald Knuth

durron597
  • 31,968
  • 17
  • 99
  • 158
  • Are you sure you close all your resources correctly etc? – fge Jul 02 '13 at 14:41
  • @fge Well I know logback is holding at least one log file open, and netty is holding a channel open (this is a client program) – durron597 Jul 02 '13 at 14:51
  • When do you take these dumps? Right after the program starts, later? – fge Jul 02 '13 at 14:54
  • @fge That dump was a couple of minutes after it started. It doesn't appear to be "leaking" just using lots of unnecessary memory – durron597 Jul 02 '13 at 14:55
  • Did you check to see if the big arrays are weakly referenced? – Stephen C Jul 02 '13 at 14:58
  • @StephenC I clicked on "Include weak refs" under Reference chains from rootset and it gave no references at all. Maybe they're scheduled to be GCed and just haven't been yet? I noticed that the [MAT example here (under step 3)](http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fgettingstarted%2Fbasictutorial.html) has similar huge arrays but the author of that tutorial doesn't mention it. Maybe it's a Java startup thing? – durron597 Jul 02 '13 at 15:01
  • You do have a puzzle there -- I can't think of anything that would produce so many large int arrays. Strings, of course, include char arrays, and byte arrays would be common in I/O objects. But int arrays??? – Hot Licks Jul 02 '13 at 15:35
  • http://javarevisited.blogspot.com/2011/04/garbage-collection-in-java.html – yams Jul 02 '13 at 15:46

0 Answers0