Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is char[] surviving so many generations, and should I be concerned?

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

like image 682
Robert H Avatar asked Jan 10 '13 14:01

Robert H


2 Answers

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.

like image 136
Peter Lawrey Avatar answered Sep 28 '22 00:09

Peter Lawrey


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.

like image 37
Madhusuthanan Seetharam Avatar answered Sep 27 '22 23:09

Madhusuthanan Seetharam