File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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

Joined: Mar 10, 2008
Posts: 1951

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: 15081

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
I agree. Here's the link:
subject: size of an object
It's not a secret anymore!