wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes SizeOf() in java 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 » Beginning Java
Bookmark "SizeOf() in java" Watch "SizeOf() in java" New topic
Author

SizeOf() in java

Chiranjeevi Kanthraj
Ranch Hand

Joined: Feb 18, 2008
Posts: 289

Hi all
I want to see the Size of the object in java.
i their any API to give that. Like in C++ we have SizeOf();

Thanks


-Chiru
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

No there isn't. There are some tricks you can use to determine the size of an object (for example see this rather dated article. But they are not things you would want to do in production code. It's more for the initial development work.

You can also use profilers to look at the size of objects.

Take a look at this google search for more discussion on the subject, as it is a frequently asked question.
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

p.s. Java 5 comes with a (basic) profiler tool built in. Take a look the SDN article HPROF: A Heap/CPU Profiling Tool in J2SE 5.0 for more info.
Sid Murrey
Ranch Hand

Joined: Jul 07, 2008
Posts: 58
With Java 6 SDK Update 7, you also get the Java VisualVM right inside the JDK package.
https://visualvm.dev.java.net/
July 8th, 2008: JDK 6 Update 7 with Java VisualVM released. Starting from JDK 6 Update 7, VisualVM is also available as a JDK tool called Java VisualVM. This way you will get a stable tool tested with respective JDK distribution. Latest Sun JDK 6 update can be downloaded here.
santhosh.R gowda
Ranch Hand

Joined: Apr 06, 2009
Posts: 296
Hi chiru,

There is no API provided to find the size of an object......
but there is an alternative way to find the size of as object
its in Runtimeclass in lang package....
Runtime obj = Runtime.getRuntime();
System.out.println(obj.totalMemory() - obj.freeMemory());
which gives you the size of an Object




Creativity is nothing but Breaking Rules
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Santosh,
Please dont http://faq.javaranch.com/java/DontWakeTheZombies
This thread is almost one year old.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
karimkhan pathan
Ranch Hand

Joined: Jul 14, 2008
Posts: 86
The reply helps......Thanks ..


karim
 
jQuery in Action, 2nd edition
 
subject: SizeOf() in java
 
Similar Threads
Sizeof For Java
Size of an Object
data types
difference between exe file and batch file
JNI issue with ByteArray