Bash.tv → GitHub → itch.io

Control memory in browser games. Ownership rules (who creates, who frees), scene and level lifecycles with complete cleanup, AbortController for listeners, pooling and preallocation, typed arrays for large data, caches with limits and WeakMap, image, audio and GPU memory budgets, disposing three.js and Pixi resources, phone memory limits and tab crashes, and verifying with heap measurements. Us...

Download skill (.zip) Files on GitHub

Game memory management

Leak detection is game-memory-leak-detection. This skill is how to structure the game so memory stays flat.

Ownership: whoever creates it frees it

class PlayScene {
  enter() {
    this.ac = new AbortController();
    const { signal } = this.ac;
    addEventListener("resize", this.onResize, { signal });         // all listeners tied to one signal
    this.offCoin = this.game.events.on("coin", this.onCoin);
    this.timers = new Timers();                                    // dt-based; dies with the scene
  }
  exit() {
    this.ac.abort();                                               // removes every listener above
    this.offCoin();
    this.bullets.releaseAll(); this.particles.releaseAll();
    this.level?.dispose();                                         // GPU resources, if any
    this.entities = null;
  }
}

Budgets (phones are the limit)

Resource Rough budget for a mobile web game
JS heap < 100–200 MB
Decoded images width × height × 4 bytes each: a 4096² texture is 64 MB
Decoded audio ~10 MB per minute of stereo 44.1 kHz. Stream music instead of decoding it
GPU textures < 150–256 MB total

iOS Safari kills tabs that use too much memory, often with no error. A big texture atlas is the usual cause.

Techniques

Verify

  1. leak-check.py cycles (restart, level change) must show flat heap and listeners.
  2. three.js: renderer.info.memory.textures / geometries return to the same numbers after each level.
  3. Long session test: 20 minutes of play on a phone through the viewer’s preview without slowdown or a crash.