-2

please let me know where does my static reference, static primitive, object reference , object itself and method itself along with class information is stored.

*please let me know who does this memory management?

*please let me know what gets stored in permgen place?

*please specify the storage space(heap or stack) which will be allocated for all the object references,object, primitive data (for both static and non-static types) for the following program.

package training;

public class Memory {


    static int var =1;
    static String s="hi";
     static Threadtutorial th;// this is another class in the same project,consider this an object.
    static Threadtutorial tt = new Threadtutorial();
    int are =2;
    int d;
    static float value;


    public static void main(String[] args) {
        // TODO Auto-generated method stub
        int a;
        int b=1;
        Threadtutorial th;// this is another class in the nsame project,consider this an object.
        Threadtutorial tt = new Threadtutorial();
        final int var =1;
 value=8;
    }
    void somemethod(){
        int ne=3;
        String something;
        Object ref;
        Object dereee= new Object();
    }
    static void another(int b){
        int c=b;
        Object ref2;
        Object der= new Object();
    }

}
amarnath harish
  • 945
  • 7
  • 24
  • 3
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. **Avoid asking multiple distinct questions at once**. – Ousmane D. May 23 '17 at 16:36
  • Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) before attempting to ask more questions. –  May 30 '17 at 17:14

1 Answers1

-1

Where things are conceptually per the JLS is one thing and deterministic, where they are physically in the JVM is another and varies with circumstances.

The easy part is where things are conceptually. Type definitions including method areas, space for static fields, and other type-level information are in the class area of heap. Method arguments and other method control information live on the stack as methods are invoked. Instances live on the heap.

Physically those things can live in various places at different times or even disappear altogether. Member variable values might live for a while on the stack or in registers while the rest of the object is not even in memory. Method calls might vanish altogether. The runtime interpreter/compiler combination has wide leeway in how it handles program logic.

Have you actually tried researching your question? What have you come up with?

Lew Bloch
  • 3,364
  • 1
  • 16
  • 10
  • 1
    yes, i actually read about heap and stack memory, but the think is i need to know where the static reference for primitive and object is saved? and where its values is saved if its object? does it change if we assign object's value in the static block and non-static block? – amarnath harish May 25 '17 at 16:44
  • 1
    Any member reference if "saved", i.e., stored a variable, is stored in the class if `static`, or the instance if not. Local variables reside on the stack. Reference expressions reside in registers or stack. I don't know what you mean by "where its values is saved if its [sic] object". Objects and classes reside in heap. Static and instance _initializer_ blocks don't change any of that. I'm assuming what you mean by "static block" but I don't know what you mean by "non-static block". What sources have you looked up for this question? Are you willing to share the links? – Lew Bloch May 25 '17 at 21:19
  • So, im assuming all local variable's refernce (not object itself) and method parameters gets saved in stack for each thread..what do mean by "Objects and classes reside in heap". i understand object reside in heap.but what do u mean by classes. do they get saved in permgen space as byte code? where exactly static reference variables and its values gets stored ? – amarnath harish May 28 '17 at 05:24
  • Are you sure you want to learn all about Java's memory system in a comment thread on SO? Is that even possible? – Lew Bloch May 28 '17 at 07:07