Lesson content
Read, practise, then check your understanding
Objects generally live on the heap; each invocation has a stack frame holding execution state and local values. The JVM may optimize placement while preserving observable behavior.
Reachability, not scope
List<byte[]> retained = new ArrayList<>();
// Retaining references keeps arrays reachable and prevents reclamation.
retained.add(new byte[1_000_000]);
retained.clear();
Collectors find objects unreachable from GC roots and reclaim them; timing is intentionally unspecified. Strong, soft, weak, and phantom references have different reachability roles. Java can still leak memory through caches, listeners, thread locals, and static collections. Heap sizing and collector choice are operational decisions driven by latency/throughput measurements. GC manages memory—not files, sockets, native handles, or business lifecycle—so close resources deterministically.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.