17

I am checking out the profiler in NetBeans for the first time, and I had noticed this morning that I had over 1700 surviving generations shown via the Monitor profiler, but a constant heap size. In doing some reading I found this article that discusses using the NetBeans profiler to uncover leaks.

So, in following the articles advice I started a memory profiler. In looking at the results I found that char[] accounts for the majority of surviving generations. Currently as of this post, char[] is at 22 generations and counting.

Now some posts (comment by OldCurmudgeon near the bottom) indicate that if my heap is stable there is no leak, yet others say that if the generations continue to grow there is. So I am a bit confused to which is right.

So, my question is:

Based upon the following screen shots should I investigate potential memory leaks further?

Memory(Heap) Memory(Heap)

Memory(GC) Memory(GC)

Live allocated objects Live allocated objects

Community
  • 1
  • 1
Robert H
  • 10,659
  • 17
  • 63
  • 102

3 Answers3

8

The char[] will probably be held by String objects. They could be created anywhere for any purpose e.g. the profiler and JMX use them so a process which does nothing will show these (and a growing heap)

Note: all the String literals and names of Classes etc will survive until the ClassLoader is unloaded (this can the life of the program)

To determine if your heap usage is growing you should look at how much is retained after a full GC. Have a look at the bottom of each dip and it appears the same to me. The other information is useful for performance tuning, but is not an issue in itself.

Peter Lawrey
  • 498,481
  • 72
  • 700
  • 1,075
  • Interesting, do you have any recommended resources for reading up on profiling? – Robert H Jan 10 '13 at 14:57
  • 2
    I can't say I have come across any. I would recommend getting an evaluation version of a commercial profiler like YourKit to see what difference it makes. e.g. it doesn't use the heap to do it's work so it does create "noise" on the heap. – Peter Lawrey Jan 10 '13 at 15:00
  • 2
    I would suggest profiling simple programs where you understand everything which it is doing to see how that looks for CPU and Memory profiling. This can help you understand what complex applications are doing (and know what to ignore, which quite a bit ;) – Peter Lawrey Jan 10 '13 at 15:01
  • Thanks, I'll follow up on that advice. – Robert H Jan 10 '13 at 15:02
  • Part of the problem is what profilers should do and what really happens when you profile an application e.g. it will change the way the program behaves, slowing it down and it can't measure small intervals of time. – Peter Lawrey Jan 10 '13 at 15:03
2

I also faced these lingering char[] during my profilings. After a long analysis I came to a conclusion that many of these are the char arrays of the String constant pools.

2

Without looking at the code, one can't tell. There are programs which uses TB of memory, and they work well because it's not a memory leak, it's just how the program works.

The Netbeans documentation just defines what surviving generations are, not how to use that figure to spot a memory leak. Moreover, a char[] is just the content of a String, and it can be retained a very long time (even as long as the main thread).

There's no magic bullet to find leaks. You should run your program under a feasible load, and see if the memory usage is consistent with the expected pattern. If it's not, then you have a problem, but without any context that graph doesn't mean anything.

Raffaele
  • 19,761
  • 5
  • 42
  • 81