Skip to the workspace
Pebellslearn by building
Memory Management  ›  Lesson

Memory Lifecycle

Memory Management 12 min

javascript / Memory Lifecycle

Explore each scene at your own pace.

01 · Memory Lifecycle

Memory Lifecycle

Memory Lifecycle

Memory use has a lifecycle: values are allocated, referenced and used, and may later become unreachable. JavaScript manages reclamation rather than requiring explicit free calls.

A variable losing one reference does not necessarily make the object unused everywhere.

See the mechanism

Walk through the modelMemory LifecycleAuthored snapshots of the example; use Run below to test the code.
articleobject A
The binding refers to the new record.
1 of 3

Follow one example

javascript

The saved array still refers to the record after article is set to null. Removing one reference does not delete the object. When no relevant strong path from the program’s roots reaches an ordinary object, it may become collectible. This is a reachability model, not a claim that a particular collection happens at the next statement.

Predict, change and check

Predict: Would clearing article make saved[0] disappear automatically?

Test your explanation: Clear saved.length after printing, then draw which reference paths remain. Do not use process memory readings to infer collection at a precise statement.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

Follow ownership from a root

Memory lifetime is about allocation, use and whether values remain reachable through references. A local reassignment can remove one path without removing other paths from a cache, closure, event listener or global collection. Source-code scope ending does not guarantee every referenced value disappears immediately.

Draw the path that keeps a large object alive before changing code. A cache may be intentionally retaining useful data, so distinguish a useful owner from an unbounded or forgotten owner. Choose a release policy and test that the application removes its own references when that policy says it should.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.