Java memory model - the difference between stack and heap

A difference: memory allocation strategy (three kinds)

  1. Static memory: determines the storage space requirements for each data object at runtime compilation. Fixed spatial allocation at compile time, it does not allow nested / recursive code.
  2. Stack storage: a data area needs compile time is unknown, the run -time module determines the size of the inlet.
  3. Storage stack: compile time or run time, the module can not determine the size of the inlet, dynamic allocation. For example: a variable-length string or object instance

Difference between the two:

  1. Management: Heap need to GC, the stack is automatically released
  2. Space: heap> Stack
  3. Related debris: fragments generated far less than the stack heap fragmentation generated
  4. Allocation: stack supports static / dynamic allocation; heap only supports dynamic allocation
  5. Efficiency: Efficiency Stack> heap efficiency

Guess you like

Origin www.cnblogs.com/starstarstar/p/11234333.html