[Interview Question] The Structure of the Java Stack & Heap
Organizing interview questions about Java's Stack and Heap
Java Memory Structure
See JVM Structure and Principles
The Java Runtime Data Area we built to run the application is located in memory
-
The PC Register, Native Method Stack, and Method areas are shared by all threads.
-
Only the Stack and Heap regions are thread-specific
Structure of the Heap
Eden → Survivor → Old
The objects are moved in the above format, which is basically the order of creation.
The role of the Garbage Collector
-
Eden: a place where Java objects are stored as soon as they are created.
-
Survivor & Old: space where objects are moved based on their degree of reference
-
Mark and Sweep: uses the Mark and Sweep algorithm.
Minor Garbage Collector
Responsible for moving the Eden and Survivor regions (Young Generation) based on object references if their memory exceeds the allowable amount.
Major Garbage Collector
Responsible for removing all unreferenced objects and reclaiming memory when the memory of the Old region (Tenured Generation) exceeds the allowable limit.
- Stops all threads except the one running the garbage collector during the deletion process ('Stop-The-World')
Structure of the Stack
Base Type + Local Variables + Parameters
In the case of a parameter, it is used in the form of a reference to an object in the Heap region with the object's address value.
→ If the parameter refers to a different object, the address value will only be different, and the object stored in the Heap will not disappear immediately! (Hold until the Major GC is executed)
Note
댓글 작성
게시글에 대한 의견을 남겨 주세요.