my dog learned polymorphism*
The moose likes Beginning Java and the fly likes size of an object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "size of an object" Watch "size of an object" New topic
Author

size of an object

pradeepta chopra
Ranch Hand

Joined: Jul 05, 2008
Posts: 137
how do we find out the size of an object?
somewhere i read that the way is to convert into string and note the length.
but i find a string like @1fee6fc???
now wat does the above string represent??
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1763
    
    7

It's a bit more involved than that, I'm affraid.
Take a look at this Javaworld article.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14190
    
  20

The "@1fee6fc" that you see when you call the toString() method of class Object is the hash code of the object in hexadecimal; it does not have anything to do with the size of the object in memory (or the address of the object, as some people think it is).

There is no easy way to find the size of a Java object in memory.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
GeeCON Prague 2014
 
subject: size of an object