VB-441: The page frees a rebuilt farm’s drawings (quick start at the uncapped speed ran out of memory)
Status: done (2026-11-15)
Priority: 1
Size: S
Design ref: none (the page’s drawing; src/page/settlement.js, buildFarms and clearSettlement)
Goal: buildFarms takes down and redraws every farm, fence and pawn when the simulation marks a change, and destroyed what it took down with destroy({ children: true }). In PixiJS 8 that leaves each Graphics’ own context alive (Graphics.destroy frees it only with no options, true or { context: true }), and the renderer’s cache of contexts (graphicsContext._gpuContextHash) then keeps the geometry of every fence and house ever drawn. On the quick start at the uncapped speed the tab’s heap passed 1.4 GB by year 3 and the tab died within a few years (Kim, 14 November). The drawings are destroyed with their contexts.
Acceptance criteria:
buildFarms and the settlement’s clearing destroy what they remove with its context.
A check in tests/browser.js: after nine rebuilds of the farms, each drawn, the renderer holds about as many Graphics contexts as after one. It fails without the fix.
Quick start at the uncapped speed, before and after: the contexts held and the heap, reported below.
Notes:
15 Nov 2026: found from Kim’s report that the quick start crashes at the uncapped speed within a few years. Headless the same run holds 26 MB at year 8 and never fails; the growth is the page’s. A sampled heap profile of the page at year 5 (1.28 GB) put nearly all of it under buildFarms, addFence, drawFence and PixiJS’s updateGpuContext.
The destroy call dates from VB-213 (10 November), so the leak was latent. What made it bite: rebuilds asked for rose from about 56 to 85 a game year on populous tiny, seed 18, over 3 years (10 November against now), mostly newly broken fields (sim/fields, broken) and scrub cleared (sim/spread, clearScrub). Rebuilding only what changed is VB-442.
Numbers, quick start (populous, tiny, one of its seeds) at the uncapped speed in Chromium, the test fixture’s one drawn frame a second, about 100 seconds of running. Before: contexts held 498 at year 0.24, 6,222 at year 3.54 (about 1,800 a game year); heap 236 MB rising to 1,366 MB at year 3.09. After: contexts between 57 and 113 throughout, heap between 82 and 195 MB to year 5.57. The two runs drew different seeds, so the years reached (3.5 and 5.6 in the same time) are indicative only.
The check: 508 contexts after nine rebuilds against 188 after one without the fix; passes with it.
No simulation code, state field, loop or counter changes. Not measured: a real GPU (the runs are software-rendered), where each context also held buffers on the card.