Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Determine an Objects Size ?

 
Faisal Khan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Thomas Smets
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic