This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Object Memory- Runtime 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 "Object Memory- Runtime" Watch "Object Memory- Runtime" New topic
Author

Object Memory- Runtime

jack nick
Ranch Hand

Joined: Jan 11, 2001
Posts: 96
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

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
jack nick
Ranch Hand

Joined: Jan 11, 2001
Posts: 96
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

Joined: Sep 29, 2000
Posts: 8521
How about taking a before and after shot of the used memory?
sharad goswami
Ranch Hand

Joined: Jan 18, 2001
Posts: 51
AM NOT SURE.BUT U CAN USE DECODE OF WRAPPER CLASSES ALSO READBYTE in of higher stream in case of file.


Stop The World I Want To Get Off.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209

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

Joined: Jan 11, 2001
Posts: 96
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

Joined: Jan 18, 2001
Posts: 51
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.
 
subject: Object Memory- Runtime
 
Similar Threads
Array doubt
dynically craeting the object
Why Compiler eror here?
How to limit the size of a object in terms of MB ?
Please brief on JavaScript architecture