• Post Reply Bookmark Topic Watch Topic
  • New Topic

Too many char[] instances.

 
Yellen Seram
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are too many char[] instances created when an EE application is deployed and running in a web server?

I came across this while running the virtualvm profiler. I have an enterprise application (Spring and stuts based using hibernate and customised caching implemented as well). I found that among the various live object instances created, the ones taking up maximum of the heap memory are char[] instances and String objects. I have the max. heap size at 1GB and these instances are taking up almost 60% of the used heap space (around 250mb).
I'm just curious about this and would appreciate if anyone could help me understand this better.
 
manoj r patil
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In general String/char[] objects occupy max heap size which is common. This is where performance engineer focus on while tuning it.

If you will check the implementation of String, you will find internally it used char[] to hold the literal.

 
Yellen Seram
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, String does use char[] internally for holding the literals. However, the profiler shows that the String object instances are taking some heap space and the char[] instances are taking their own heap space. Shouldn't it be that the heap spaces taken by the String objects and some of the char[] instances are common?

The way the memory utilization being depicted by the profiler is confusing me a little.
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yellen Seram wrote: Shouldn't it be that the heap spaces taken by the String objects and some of the char[] instances are common?


No, because Strings are immutable, but character arrays are not. That's why the StrinngBuffer/StringBuilder classes exist - to help you conserve resources which composing Strings.

Actually the array parts of character arrays are also immutable, but their contents aren't. Which is why the string pooling mechanisms can't optimize them,
 
Yellen Seram
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmmm.. that makes sense...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!