LLearnCode
Academy/javascript/Browser and asynchronous engineering

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.

Loading progressEvidence grows with practice
Useful preparation · 1 prerequisite

Use this as a map, not a lock. If these ideas are familiar, continue.

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.

  1. Keep handles for listeners, timers, frames and workers.
  2. Return a cleanup function from a setup boundary.
  3. Make cleanup safe to call more than once.
  4. Separate pure state updates from resource-owning adapters so rules remain easy to test.
Read the codejavascript · educational example
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();
  1. Acquire

    The function creates one interval and keeps its handle.

  2. Release

    The returned function stops that interval.

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