• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

visualvm is reporting 'byte[]' and 'char[]' as classes in memory profiler

 
Dan Peters
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a tomcat web app that is eating up more memory than I would like. I'm profiling tomcat with visualvm, and in the memory profiling section, the top two 'classes' it's showing me are 'byte[]' and 'char[]'. I haven't done a lot of profiling before, so this is a bit confusing. Those seem to be references to an array of bytes or chars respectively, I'm just confused as to why the profiler is showing me those instead of actual class names.

As a bit of background, my application is using the spring MVC web framework. I have JSP pages on the frontend, and I'm using Hibernate with a mySQL DB for persistent objects on the back. As an example, when I go to an 'edit' page, a backing object is provided, and the heap jumps like 100MB. The object itself isn't holding anywhere near that amount of data, nor is it referencing other objects that would take that much memory as near as I can tell, so I'm stumped as to what's happening. I confess that the inner workings of hibernate and spring are somewhat of a mystery to me, so maybe I'm missing something there.

So in short, can anyone comment on why the profiler is reporting arrays of bytes and chars as classes in the memory profiler? Any other related comments are of course welcome as well!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's simple - in Java, arrays are objects. You even allocate them using the "new" operator. As a corollary, byte[] and char[] would be the "class names" to display (putting that in quotes, because that's just a conceptualization).
 
Dan Peters
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply. Of course, that makes sense! I was still thinking about arrays from a C++ perspective without realizing it. I searched through the code for declarations of 'byte[]' or 'char[]' and only hit one instance of 'byte[]', which wasn't related to the object I'm providing to back the form, and no declarations of 'char[]' in the entire code base! I'm baffled by this. Any suggestions of how I can narrow down on where these array objects are coming from?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the great things about Java is you can get the source code! Look at the String class for example:



A String object must have a char[] to hold the characters.

Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic