Skip to main content
PProfileMatch
← Path

Advanced Java · Java Heap, Garbage Collection, Records and Sealed Classes Explained

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Parking bay at the dog park

Trick to keep in mind+3 XP

The stack holds the leash, the heap holds the dog.

A local variable, including an object reference, lives in the stack frame of the running method and disappears when the method returns. The object it points to is allocated on the heap, which is shared by all threads and reclaimed by the garbage collector. Metaspace is a third area, and it stores class metadata rather than your objects. Passing an object to a method copies only the leash.

Read it once, then a question tests whether the trick stuck.