[Java Application Performance and Memory Management] Chapter 4 – the stack and the heap

Published by

on

Stack

  • First-In-Last-Out structure.
  • Stores local variables, reference variables, as it lives for short lifetime.
  • It only stores simple data types like primitives(e.g. int, double, ..) . It doesn’t save complex data types like objects.
  • Each Thread has its own Stack
    • Data on a stack cannot be accessed from other threads

Heap

  • Objects are stored on the heap.
  • Heap is shared across all threads.

Example of Stack and Heap

Reference

Leave a comment