Unity WebGL "exception: Out of memory": the 2GB heap your browser build silently outgrew, and the abort you should be catching
Problem
The WebGL build runs for minutes, then dies in the browser console — most often during a scene with heavy textures or after the player has been playing a while:
exception: Out of memory
Aborted(OutOfMemory: Cannot enlarge memory arrays)
UnityLoader.js:4 Uncaught (in promise) abort("Out of memory") at ErrorDesktop builds of the same content never come close to a memory limit, which is what makes this one feel like a browser bug. It is not.
Root cause
Unity's WebGL runtime allocates a fixed-size heap for all managed memory, asset data, and the wasm linear memory combined — capped by WebGL Memory Size in Player Settings (default 256MB, maximum 2032MB in older Editor versions, 4GB ceiling with wasm64-era runtimes). There is no GC-powered escape hatch: when the heap cannot grow by a requested chunk, the runtime aborts the whole program, and that abort surfaces as the console error above.
The usual triggers, in order of how often we found them: uncompressed RGBA textures (a 4096x4096 RGBA32 texture is 64MB of heap the moment it loads), audio loaded fully into memory instead of streamed, and Resources.Load of everything at startup because it was convenient during development.
<script>
var Module = {
onAbort: function (error) {
… 8 more lines in the fix🔒 the fix — including 3 code blocks — is members-only. $1/mo unlocks everything.