• 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

Object Memory- Runtime

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,
Kwow using the Runtime class I could get the total amount of memory and the used memory of the JVM. But is there any way to find out how many bytes does a specific object take in the memory.
Thanks in Advance
Jack
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure how to do that.
Why in the world would you want to know such a thing?
Surely there is something that you are trying to ACCOMPLISH with this question.
 
jack nick
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cindy,
Know this sounds like an out of the way task to be doing, but was just messing around with one of my project just to see how much memory my application was taking, then I got about wondering how much each of my objects may be occupying, hence the question. Though not critical would be nice to figure out if this CAN be done.
Thanks anyway cindy
Jack
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about taking a before and after shot of the used memory?
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AM NOT SURE.BUT U CAN USE DECODE OF WRAPPER CLASSES ALSO READBYTE in of higher stream in case of file.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

c'd be naive, but why not try serializing the object into a file and see how much space it occupies :-)
w'd give you some idea?
karthik.
 
jack nick
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,
Thanks for your suggestion. Basically I took a shot before and after the creation of the object and also tried serializing the object, both showed me approx the same some bytes up and down.
Bye
Jack
 
sharad goswami
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here u are.use freememory() and totalmemory() methos of runtime.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic