| | |
JRE vs Class Instances in RAM
![]() |
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.
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?
How many people have code in their Sigs?
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.
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.
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: how to instal netbeans
- Next Thread: drag and drop upload applet
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application arguments array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class client code color component count database derby design eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui homework html ide if_statement image integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list macintosh map method methods midlethttpconnection mobile netbeans newbie nullpointerexception object open-source os problem producer program programming project projectideas property read recursion reference replaysolutions ria scanner search server set size sms sort sourcelabs splash sql sqlite stop string swing testautomation threads transforms tree ui unicode validation windows






