Java Memory Model
7 Topics
1
Heap vs Stack
Understand where objects live, stack allocation, thread stack frames, and dynamic allocations.
Commonly tested on heap vs stack variable allocation, parameter passing, object reference locations, and StackOverflowError vs OutOfMemoryError.
2
Garbage Collection
Understand JVM automatic memory management, reachability, GC roots, and generations.
Focuses on GC root definitions, object reachability stages, and the generational hypothesis (Young vs Old gen).
3
GC Algorithms
Compare modern Garbage Collectors: Serial, Parallel, CMS, G1, and ZGC.
Commonly tested on GC algorithm selection: G1GC vs ZGC latency limits, and Stop-The-World pauses.
4
Memory Leaks
Identify how memory leaks occur in Java, analyze heap profiles, and prevent resource leaks.
Commonly tested by presenting a leaky class (e.g. custom stack using array without nulling out references) and asking you to fix it.
5
Reference Types
Understand Strong, Soft, Weak, and Phantom references and their interaction with the GC.
Commonly tested on implementing caches (e.g. WeakHashMap) and understanding phantom references with reference queues.
6
JVM Memory Structure
Learn the JVM Runtime Data Areas, Metaspace, Stack, Heap, and Program Counters.
Commonly tested on JVM memory regions, the change from PermGen to Metaspace, and heap subdivision.
7
Memory Tuning
Tune heap sizes, generation ratios, and GC parameters for optimal performance.
Commonly tested by presenting latency profiles or OOM logs and asking you to select the correct tuning flags.