JRE vs Class Instances in RAM

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2005
Posts: 74
Reputation: Cudmore is an unknown quantity at this point 
Solved Threads: 5
Cudmore's Avatar
Cudmore Cudmore is offline Offline
Junior Poster in Training

JRE vs Class Instances in RAM

 
0
  #1
Apr 10th, 2007
Hey! There has been a question on my mind for a while regarding the JRE and the class loader (or, loading classes into RAM if it's different).

Java classes define variable members, methods, and subclasses. I know that when you create a new instance of a class, memory is allocated for the primitive values defined in the class, as well as for the pointers of any objects, etc..

What I'm wondering is, when you create a new instance of a class, and then create another, and then another, are separate copies of all the members made each time? Like, if methods exist in the RAM as bytecode, does that bytecode exist with each instance of a class, or is this managed by the JRE in an organized fashion, saving memory, where individual methods exist only once in RAM at any given time during a program's execution?

Thanks for your replies. I would love to read into this if someone could post a link to the details.
Last edited by Cudmore; Apr 10th, 2007 at 11:35 pm.
synchronized (theWorld) { System.out.println ("It's all mine..."); }
How many people have code in their Sigs?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: JRE vs Class Instances in RAM

 
0
  #2
Apr 11th, 2007
Nope. The memory space for methods, like that for static members, is allocated only once as part of the Class instance associated with the class which is shared by all instances of that class through an implicit member reference.

Of course some memory is allocated for each instance actually running a method to store method arguments and method local variables.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 1075 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC