Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my Java heap is with so many char[]

I have a web application in Tomcat where I do many String operations (substring, indexof, trimming, etc.). I made a heap dump with jmap and I loaded it using VisualVM and I realized that near 50% of my heap memory usage is with char[], Why the char[] are taking that memory usage?, should I be concerned?, is it something related to String pools?enter image description here

like image 765
Nestor Hernandez Loli Avatar asked Dec 04 '13 23:12

Nestor Hernandez Loli


1 Answers

Strings are internally just a char[] and some extra data. A char[] means a character array in other words it's an array that saves your string character by character. If you do a lot of string proccessing it's entirely possible that your system is fileld with char arrays.

So in short nothing to be concerned unless you system is actually using more memory then it should be. In that case you can look if there are some file structures left uncleared (hash maps or related).

like image 119
Thijser Avatar answered Sep 28 '22 12:09

Thijser