File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Howto determine Object size in memory

 
nishanta vats
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Pradeep Kadambar
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to do that in a crude fashion then something for you to try --->

Link

 
Pradeep Kadambar
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic