I have a simple script that displays images on screen. It works well on PC, but on mobile I keep running out of memory after just a few images. The images are less than 10MB’s of size, but loading one will use at least 100MB of memory. And I am unable to free that memory no matter what. I’ve read dozens of forum posts and some articles about freeing memory in webgl and I haven’t found anything that helped me.
Is there a way to display images with less memory consumption? I’ve tried few ways, all with pretty similar results. This is how I’ve most tried doing it:
It works well in Unity editor. The memory doesnt stack up. It only stacks on the WebGL build. And it wouldn’t even be an issue if the process consumed less memory but mobile devices are done after just 2-3 images. Any tips?
Hi! I am also seeing this issues. I am measuring my memory footprint using Unity-WebGL-Utilities/Assets/Plugins/WebGLMemoryStats at master · kongregate/Unity-WebGL-Utilities · GitHub. I’m seeing the used heap memory size grow continuously as I download more pictures until I reach the initially allocated wasm heap size, which then sometimes grows, sometimes doesn’t, and sometimes gives an out of memory. I am curious what you guys are using to monitor Webgl memory
How do you check one image is using at least 100MB of memory whilst loading?
Also, are building for asm or wasm?
If asm, what is the heap size you are allocating while building.
I am also looking for the right solution of continuous texture downloading and loading. In my case it would be sufficient to reuse the same texture the Downloadhandler creates. but that would mean writing a DownloadHandlerScript that performs the same worker thread decompression and such and I am not even sure if you can replicate that from managed code. Do you guys know the correct, full process by now?
Under the hood, Unity and emscripten use the dom element to load textures, but it seems that Chrome and Safari has memory leak there.
If you have to load lots of images, it’ll be better to try and use external image decoding lib. Like jpeg-js or compile libjpeg to wasm and use it