Simple answer: No. Not so simple answer: There might be something in the debug API, but I am not sure - and it certainly isn't meant for daily use. What do you need this for?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Oct 08, 2002
Thank u Ilja Preuss , i asked this just to know if we can determine the amount of memory required for our application to run
Joined: Jul 11, 2001
You could get a rough measure by using a combination of Runtime.getTotalMemory() and Runtime.getFreeMemory(). Beware, though: The result might heavily depend on the JVM used. Not only will it depend on when the GC decides to collect unused objects. Java also doesn't specify how data is implemented. For example, a char variable only has to behave as if it were a 16 bit value - JVM implementors are free to use any amount of memory (on some processor architectures it is faster to acces memory on "word boundaries", so a JVM for a 64 bit word processor might be implement to always use multiples of 64 bit).
Regarding the measurement of object size, here is an example which may be of assistance : http://www.javapractices.com/Topic83.cjp It follows the scheme of the "Java Platform Performance" book. It is designed for classes which have a no-argument constructor. (If your case does not allow this, you will need to modify, perhaps using the Constructor.newInstance method). [ October 19, 2002: Message edited by: John O'Hanley ] [ October 19, 2002: Message edited by: John O'Hanley ]
If there is a particular class or two you are interested in, and you can modify or extend that class, you might be able to do your own instance counting, using a static field you increment in the constructor and decrement in finalize.