Heap, Stack and Object Allocation
- Stack and heap. Each thread’s stack holds call frames and locals; every object lives on the shared heap.
- Allocation is cheap. JVM allocation is a pointer bump: creating objects is fast; keeping them alive is what costs.
- OutOfMemoryError. A heap that cannot grow throws OutOfMemoryError: usually a leak holding references, not truly big data.
Garbage Collection
- Reachability. The collector frees objects no longer reachable from roots: you release references, never memory.
- Generational collection. Most objects die young, so heaps split into generations: young collections stay small and fast.
- GC pauses. Collectors trade throughput against pause time: modern ones keep pauses at milliseconds even on huge heaps.
JVM Runtime Behaviour
- JIT tiers. Code starts interpreted, then tiers up through JIT compilation as it proves hot: benchmarks must warm up first.
- JVM flags. Flags size the heap and pick the collector: a deploy setting as real as any line of code.
- Observing the JVM. The JDK ships observers: jstat, thread dumps, flight recorder: the JVM will tell you what it is doing if asked.
Before and after this level
- Before: Level 8: Concurrency: Threads and Executors, Synchronisation and Shared State, Modern Concurrent Java.
- Next: Level 10: Reflection & Language Infrastructure: Annotations, Reflection, Dynamic Language Features and Trade-Offs.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does Java Level 9: JVM & Memory cover?
Heap, Stack and Object Allocation, Garbage Collection, JVM Runtime Behaviour: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 8: Concurrency, which covers Threads and Executors, Synchronisation and Shared State, Modern Concurrent Java.