Memory Lifecycle
In short: every value's life has three stages. Allocate: space is
set aside the moment you create it (let cart = {...}). Use: the
program reads and writes it while it's needed. Release: every
reference to it is dropped, and it becomes eligible to be cleaned up.
JavaScript handles all three automatically — you never call anything like
malloc/free yourself. The one thing worth being precise about:
"release" means dropping references, not the moment memory is actually
reclaimed. The engine decides when that happens, on its own schedule,
never something your code can observe or control directly.

Watching the three stages happen
The same three stages, in order, on one ordinary object:
Nothing here is special syntax — allocation is just { ... } being
evaluated, use is just reading and writing properties, and release is
just letting go of the variable that used to point at it. Once cart is
null and nothing else references the original object, it's eligible to
be cleaned up — but exactly when that happens is not something this code
can show you.
Primitives copy, objects share a reference
Whether a value gets copied or shared affects what "the last reference" even means — a detail from the data-types lessons that matters again here:
count and sameCount are two completely independent values after this
— changing one never affects the other, and each has its own separate
"last reference" moment. Objects behave differently: assigning one
variable to another copies the reference, not the object, so multiple
variables can point at the exact same allocated memory, and it only
becomes eligible for release once all of them let go.
Quick practice
What does "allocate" mean in the memory lifecycle?
After let cart = {...}; cart = null;, is the object's memory freed at that exact line?
Why does let a = 5; let b = a; b = 10; leave a unchanged, while doing the same with two variables pointing at the same object would NOT leave the other one unchanged?
