• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Howto determine Object size in memory

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic