• Post Reply Bookmark Topic Watch Topic
  • New Topic

Understanding Memory Profiling

 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I did a memory profiling on my web application.
I don't think the tools I used is important
but I'm using JProfiler.

Apart from the my own object, I see a lot of other
objects such as:
- java.lang.String
- java.lang.StringBuffer
- byte[]
- class[]

My question is that if I have 1 instance of object called Person
with a String attribute, would the profiler report:

Person=1 instance
java.lang.String=1 instance

Or, is it just

Person=1 instance

Reason I'm asking is that I see primitive java types taking quite a
lot of spaces in the memory of my application and I'm curious
what those are.

Please comment.


Thanks in advance.
 
Virag Saksena
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.String is internally implemented as an array of characters, which might explain what you are seeing. The non-garbage primitive arrays will belong to an object. What object are they hanging off of ?
 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

That's what I thought as well.

1) But after having a second thought, the follow up question is then why
the so call Person object still take up memory spaces?
(the attributes should have been reported as java.lang.String, int, etc
and Person = 0 bytes)

2) Of course, unless the memory spaces reported on the Person object
is the total for that object. But, this would mean that the allocated
spaces for the attributes are reported in 2 places:
- the actual data type itself; eg: java.lang.String, byte[]
- the object in which the attributes belongs to; eg: Person object

On further investigation, I found out that the total memory used seems to be closer to java.lang.String + byte[] + etc + Person rather than
just Person, which is suggesting that point (2) above is inaccurate.


Please comment.

Thanks.
 
Virag Saksena
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what JProfiler is reporting as the memory numbers for person. I'd recommend you download and try JAM. It'll break out the memory used and hierarchy for individual objects.

Or if you send me the class files for person I can run it and send you the numbers.
 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Virag,

Could you please provide the link to JAM?
I tried googling and doesn't seem to see any good match.


Thanks.
 
Virag Saksena
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be able to register and download a version from http://www.auptyma.com
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!