Heap vs Stack

  • Heap is used to store objects
  • Stack is used to store method calls and local variables

Point Heap Stack
Memory type Dynamic memory Static memory
Stores Objects Method calls, local variables
Memory size Large Small
Thread safety Shared across threads Thread-specific
Memory management Garbage Collector Automatic (LIFO)
Lifetime Until object is referenced Until method execution ends

This site uses Just the Docs, a documentation theme for Jekyll.