Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2004

Tip: Looking for answers? Try searching our database.

How much memory is created on the heap if 'a' is defined?

Thread view: 
Wenfei Ye - 07 Dec 2004 20:40 GMT
class A;
A a;

How much memory is created on the heap if 'a' is defined?

Thanks,

Wenfei
ye_wenfei@hotmail.com
Hal Rosser - 07 Dec 2004 20:53 GMT
> class A;
> A a;
[quoted text clipped - 5 lines]
> Wenfei
> ye_wenfei@hotmail.com

memory is not created. its already there.
it may get allocated.
Chris Smith - 07 Dec 2004 21:09 GMT
> class A;
> A a;
>
> How much memory is created on the heap if 'a' is defined?

Using what virtual machine?  And what code, since the code you've
written above doesn't compile?  On a 32-bit platform, the declaration of
the variable 'a' would reserve 4 bytes of space, assuming that you have
validly defined a class called 'A' so that the code compiles.  Those
four bytes would only be on the heap, though, if 'a' is an instance
field.  If it's a local variable, they'll be on the stack, and if it's
static, they'll be in the static data area.  Those 4 bytes are at least
theoretically there, but compiler optimization by either the bytecode or
JIT compilers might output any equivalent code that accomplishes the
same thing (so, for example, if you never refer to 'a', then one or the
other compiler may omit it).  A 64-bit VM would reserve eight bytes
instead.

If you create an object of class A, then the answer is even more
dependent on the VM.  Generally there is somewhere between 4 and 16
bytes of overhead for the object header, plus space for any data fields.  
The class generally takes space for method vectors (sometimes called the
vtable) the method code itself (possible both the bytecode version and
one or more JIT-compiled versions), and other class description; and
this could be allocated from the same memory pool as the Java heap.  
There is a Class object as well, which can either be created lazily by
the VM or instantiated proactively.  There may be additional overhead on
either a per-class or per-object basis for garbage collection metadata,
which is part of the structure of the heap itself.

In the end, the answer is undefined.  Why do you think that you need to
know?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.