emscripten-core / emscripten-core/emscripten
Memory leak in webgl. canvases are never garbage collected. WebGLUniformLocations
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
I was chasing a problem were a simple test would allow my webgl canvas once lost, to become restored once the garbage collector ran, but in the real product, it never happened. This is what I learned after doing some memory analysis:
In the function populateUniformTable:
https://github.com/emscripten-core/emscripten/blob/bdf9e073b58892017919991a993568a9de10e557/src/library_webgl.js#L1123
the WebGLUniformLocation objects are stored in the GL.uniforms array which does not go away when a context is destroyed.
This has the effect of keeping a link to the context so it never gets garbage collected.
What should be happening is in glDeleteProgram:
https://github.com/emscripten-core/emscripten/blob/bdf9e073b58892017919991a993568a9de10e557/src/library_webgl.js#L3097
the references to the WebGLUniformLocation should be removed from the GL.uniforms array.
Either that, or all the references to GL.uniforms should somehow find their way to the program and they should be stored in the ptable object here:
https://github.com/emscripten-core/emscripten/blob/bdf9e073b58892017919991a993568a9de10e557/src/library_webgl.js#L1128
Contributor guide
Assessment
This issue has not been assessed yet.