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.
- 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.
- 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.
- 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.
- 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.