wood burning stoves 2.0*
The moose likes Java in General and the fly likes Howto determine Object size in memory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Howto determine Object size in memory" Watch "Howto determine Object size in memory" New topic
Author

Howto determine Object size in memory

nishanta vats
Greenhorn

Joined: Jun 13, 2005
Posts: 8
Actually i want to determine the size of object and dont want to use Profiler.
Can anybody help me in this regard.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You can't do that in pure Java. What are you trying to do that requires you to know the true size of Java objects?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Pradeep Kadambar
Ranch Hand

Joined: Oct 18, 2004
Posts: 148
If you want to do that in a crude fashion then something for you to try --->

Link

Pradeep Kadambar
Ranch Hand

Joined: Oct 18, 2004
Posts: 148
Here is few more for you liking ...

Link 1

Link 2

I think you can do some googling on this. There are lot of resources online.

Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Surely, one of those examples does exactly what the other example says you should not do. That is, assume that the memory used to store a primitive data type is the same as the apparent size of that data type. A Java int might be stored in 4 bytes, but it might be stored in more than 4. A short might be stored in 2, 4, 8 or some other number of bytes. You don't know.

Any attempt to measure the true amount of memory used by a Java object is full of dodgy assumptions and/or involves time-consuming and inapproximate measurement. Therefore, you should think very carefully about why you think your application needs to know the size of the object.

I have written an awful lot of Java (but hopefully not a lot of awful Java) and have never found a situation where it was absolutely required to know how big a Java object was. A different approach has always proved possible.

If you really do need to know this information, please tell us why - it will be interesting!
Virag Saksena
Ranch Hand

Joined: Nov 27, 2005
Posts: 71
If you don't want to use a profiler, you can try Auptyma's Java Application Monitor. It will dump the space used by each object to a dump file.

Further it will also provide information about objects reachable from the object.


<a href="http://www.auptyma.com" target="_blank" rel="nofollow">The Peak of Performance</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Howto determine Object size in memory
 
Similar Threads
How I get byte[ ] from Object?
no of instances and Object's size
Memory optimization tips needed
Size of a session object
What is in the Session?