production · 24 minute study
Give every resource an owner
Repeatedly entering a page or game should not multiply listeners, timers, audio nodes or retained state.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Only the current request may commit — A slow old search can overwrite a newer result; account changes make the same bug a privacy boundary problem.
First, build a mental model
Acquiring a resource creates a lifecycle obligation. The same owner that starts it must know when to stop it, including failures and partial setup.
- Keep handles for listeners, timers, frames and workers.
- Return a cleanup function from a setup boundary.
- Make cleanup safe to call more than once.
- Separate pure state updates from resource-owning adapters so rules remain easy to test.
function startTicker(onTick) {
let stopped = false;
const timer = setInterval(() => onTick(Date.now()), 1000);
return () => {
if (stopped) return;
stopped = true;
clearInterval(timer);
};
}
const stop = startTicker(time => console.log(time));
stop(); stop();- Acquire
The function creates one interval and keeps its handle.
- Release
The returned function stops that interval.
- Repeat
The stopped guard makes repeated cleanup harmless.
Production thinking
Take this beyond the example.
Maintain a resource ownership checklist for complex screens and games. Cleanup on unmount, pause, disconnect and setup failure; measure retained objects when investigating memory growth.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.