• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object Memory- Runtime

 
jack nick
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • 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
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • 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
  • 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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about taking a before and after shot of the used memory?
 
sharad goswami
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
here u are.use freememory() and totalmemory() methos of runtime.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic