aspose file tools*
The moose likes Java in General and the fly likes How to Determine an Objects Size ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Determine an Objects Size ?" Watch "How to Determine an Objects Size ?" New topic
Author

How to Determine an Objects Size ?

Faisal Khan
Greenhorn

Joined: Nov 05, 2001
Posts: 2
I need to know that how can i determine the actual size occupied by an object in memory.Either via any method specified in Java API or any implementation by JVM.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
They were just talking about an objects size in Beginner yesterday.
You might try using the search link at under the two buttons above. There have been LOTS of conversations on this topic in Beginner as well as Intermediate.


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

Joined: Dec 11, 2001
Posts: 111
Have you already tried to simply look at the long freeMemory() or long totalMemory() &see how you could use these ?
Say doing smthg like :

Running the program gives :
Memory used is : 1130416
Average size is : 11 bytes
Press any key to continue...

Changing the line to

Ten times more objects gives :

Memory used is : -4076792
Average size is : -4 bytes
Press any key to continue...

Hope this helps !


Thomas Smets
Just another developper
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to Determine an Objects Size ?