Learning paths / How memory gets freed

How memory gets freed

A scope ends, a refcount drops, a GC runs alongside you, or stops the world.

Start: step 1

4 steps · progress is saved in this browser

  1. Rust frees memory at the end of a scope, not laterRust · BasicsNo garbage collector. Each value is freed by its owner, at a line you can point to, on the owner's thread.
  2. When Python frees an object, and when it waits for the collectorPython · Intermediatedel frees an object the moment its last reference goes. Two objects that point at each other stay in memory until the cycle collector runs.
  3. Go's garbage collector runs while your goroutines runGo · AdvancedTwo brief stop-the-world steps bracket a concurrent mark. The goroutine that allocates starts the collection and helps mark; the others barely notice.
  4. A young GC pause stops every Java threadJava · AdvancedWhen main's allocation doesn't fit, it asks for a young collection. Every Java thread stops at a safepoint while GC threads copy the live objects.

All learning paths · All scenarios