Oversimplifying a bit but webassembly has a 4GB memory limit, and in practice you can't even use that much. Also unlike a desktop build, WASM builds can't move data from memory into swap space as they run out of RAM.
What I'm getting at is it's quite possible that you have a memory leak in the desktop build too, it's just much harder to run out of memory in that environment.