• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

Every running Java program needs memory for code, objects, method calls, and metadata. Without a well-defined memory model, different JVM implementations would allocate and organize memory differently, breaking the platform independence promise and making performance unpredictable.

Core Idea

The JVM divides memory into several runtime areas: Heap (all objects and arrays), Stack (each thread has its own stack for method calls and local variables), Method Area (class metadata, static variables, constant pool), and native areas (program counter register, native method stacks).

How It Works

When a method is called, a stack frame is pushed onto the thread’s stack containing local variables, operand stack, and frame data. New objects are allocated on the heap (Eden space in young generation). Class structures are stored in the method area (meta space in Java 8+). The JVM’s memory manager coordinates allocation and garbage collection.

Visual Explanation

java_memory JVM JVM Memory Areas Heap Heap - Objects - Arrays - Shared by all threads JVM->Heap Stack Stack (per thread) - Local variables - Method calls - Operand stacks JVM->Stack MethodArea Method Area - Class metadata - Static variables - Constant pool JVM->MethodArea PC PC Register (per thread) JVM->PC Native Native Method Stack JVM->Native

Semantic Network

semantic_memory THIS Memory Management GC Garbage Collection THIS--GC builds into OBJ Object Allocation THIS--OBJ builds into THREAD Multithreading THIS--THREAD related PERF Performance THIS--PERF related

Key Properties

  • Heap shared: All threads share the same heap; objects are visible across threads
  • Stack is thread-private: Each thread has its own stack, isolated from others
  • Automatic management: The JVM handles allocation and garbage collection — no manual free()
  • Configurable sizes: Heap and stack sizes are set via JVM flags (-Xmx, -Xms, -Xss)

Connections

Edge Cases & Gotchas

  • StackOverflowError: Infinite recursion or deep call chains exhaust the stack
  • OutOfMemoryError: Heap is full and GC cannot reclaim enough space
  • Metaspace (Java 8+): Replaces PermGen — grows dynamically by default, but can still exhaust native memory
  • Memory leak: Objects held by unintended references prevent GC — common with collections, listeners, caches