Following are points you need to consider about memory allocation in java.
Note: Object and Object references are different things.
1)There is new keyword in java used very often to create new object. But what new does is allocate memory for the object of class you are making and returns a reference.
That means whenever you create an object as static or local, it gets stored in HEAP.
2) All the class variable primitive or object references (which is just a pointer to location where object is stored i.e. heap) are also stored in heap.
3) Classes loaded by classloader and static variables and static object references are stored in a special location in heap which permanent generation.
4) Local primitive variables, local object references and method parameters are stored in Stack.
5) Local Functions (methods) are stored in stack but Static functions(methods) goes in permanent storage.
6) All the information related to a class like name of the class, Object arrays asscociated with the class, internal objects used by JVM (like java/lang/Object) and optimization information goes into the Permanent Generation area.
7) To understand stack, heap, data you should read about Processes and Process Control Block in Operating Systems
NOTE :Permanent Generation area has been removed in JAVA 8. All the things which were getting stored in permgen are now moved to Metaspace memory area, which is part of native memory.
Note: Object and Object references are different things.
1)There is new keyword in java used very often to create new object. But what new does is allocate memory for the object of class you are making and returns a reference.
That means whenever you create an object as static or local, it gets stored in HEAP.
2) All the class variable primitive or object references (which is just a pointer to location where object is stored i.e. heap) are also stored in heap.
3) Classes loaded by classloader and static variables and static object references are stored in a special location in heap which permanent generation.
4) Local primitive variables, local object references and method parameters are stored in Stack.
5) Local Functions (methods) are stored in stack but Static functions(methods) goes in permanent storage.
6) All the information related to a class like name of the class, Object arrays asscociated with the class, internal objects used by JVM (like java/lang/Object) and optimization information goes into the Permanent Generation area.
7) To understand stack, heap, data you should read about Processes and Process Control Block in Operating Systems
NOTE :Permanent Generation area has been removed in JAVA 8. All the things which were getting stored in permgen are now moved to Metaspace memory area, which is part of native memory.
No comments:
Post a Comment