Cited -Java area of memory, the stack memory and heap memory, respectively, what kind of scene applicable, and why?
- Stack: program to solve operational problems, namely how to implement the program, or how to handle the data.
- Heap: The solution is data storage problems, namely how to put the data, where to put.
Reference links https://www.cnblogs.com/gdufs/p/6407432.html
Run-time data area
Thread isolation runtime data areas: program counter, Java virtual machine stack, native method stacks
- Program Counter: the row number designator bytecode currently executing thread, since the thread private, so that after the handover by the program counter thread can restore the correct position of the execution.
- Java virtual machine stack: Each method creates a stack frame at the time of execution. Each method call to complete the process from execution on a stack frame corresponds to push the stack in a virtual machine process stack.
- Native method stacks? todo
Threads share of run-time data area: Java heap, the method area (which contains the runtime constant pool)
- Java heap: Store object instance. The main area is managed by the garbage collector.
- Methods District: storing virtual machine has been loaded class information, constants, static variables, the time compiler to compile the code and other data. ?
- Runtime constant pool: is part of the method area. ? todo
An OutOfMemoryError
Virtual machine memory when running several other areas in addition to the program counter are OutOfMemoryError (OOM) exception may occur.