943,829 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1286
  • Java RSS
Apr 10th, 2007
0

JRE vs Class Instances in RAM

Expand Post »
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.
Similar Threads
Reputation Points: 20
Solved Threads: 6
Junior Poster in Training
Cudmore is offline Offline
74 posts
since Nov 2005
Apr 11th, 2007
0

Re: JRE vs Class Instances in RAM

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: how to instal netbeans
Next Thread in Java Forum Timeline: drag and drop upload applet





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC