Edit - Firefox 52 seems to have smoothed this issue out. You can still memory leak if you are rapidly refreshing your browser. Scene changes don’t seem to increase memory.
I can’t release many details about my project or rather anything at all but here’s the problem:
If I load up my game in the browser and REFRESH the browser page after the game loads, it will add to the total memory used my browser (in task manager).
So let’s say Firefox is using 480 K after I open my game. I will refresh my game, now it’s using 660 K, I refresh my game now it’s using 900 K, I refresh my game and now it’s over 1 million K.
It will never go down and the browser will inevitably crash due to memory overload. If I do NOT refresh the tab my memory stays stable, however. It’s also worth noting that I need to physically close the web browser before the browser decides to release the memory used by the project.
These problems did not exist in the web player build of this game so it is specifically WebGL. But since webplayer is phased out in both Firefox and Chrome I must convert my game to WebGL platform now and have succeeded with everything except this one major issue.
As for the Memory Settings in the Build Settings, I’ve set it to the lowest value needed to run the game reliably and this issue is still a problem.
Things I have tried:
1: Played with memory settings and have managed to set it to the lowest value required to run the game.
2: Setup a preload scene that contains only 1 object and a script that does a load scene async AFTER I perform manual garbage collection.
3:Tested it on an empty project with nothing but a camera on scene. It gained about 100 K per tab refresh until around 1.8 million K when Mozilla starts to crash.
I’m not even sure if there’s a solution to this but if it’s doing it on an empty project I know it ain’t my game per-say.
Edit - Confirmed to not be doing this on Chrome but just Mozilla. Doesn’t help me much since having it functional on Mozilla is incredibly important. Edit #2 - Confirmed that Firefox memory usage is going up just from SCENE CHANGING so it isn’t ONLY from refreshing the browser page.
I see the same problem, If you refresh the browser (for example to force it to load in a new build) it doesnt free the memory it was using before, it just keeps using more memory until it crashes, how smart is that?
Also another problem is that if you make a WebGL build, then load it into the browser, then you make some code changes, build again and try to go to the same web page again to load the new build, it doesnt load the new one, instead it keeps using the previous cached build. Unless you manually clear the cache, it keeps using the old one even if you exit the browser. So im forced to keep clearing the cache, or set the cache to 0 bytes in the browser settings.
I dont know how many users will want to do this, constantly clearing their cache or setting it to 0.
Just a comment on the caching. It can be configured so that the client has to check with the server if the files are newer. In IIS you can add the following to a web.config file which is put in the same folder as your index.html.
<system.webServer>
</system.webServer>
This means that since max age is 0, the client must always check with the server if the file is newer instead of just using the cached version.
***Edit, i must check but it seem that some client can get a 304 code by using this. I just got a report from one player. Everything is fine for me and some of my friends that i have contacted but it happen at one of my player.
I appreciate the advice but is this going to fix the memory issue with scene changing as well? That is a serious big deal. I can tell my gamers not to refresh the browser tab too much or it will crash the browser but I need scene changes to work. Especially because of the big risk of data loss with serialization. I can already hear the bug reports flying in, “Your game caused my browser to crash and I lost my data!!”
Maybe you can try using scene asset bundle (loads the scene from a remote server instead of having it in the build), Im doing that now, but i havnt checked if its leaking memory each time i change scenes by loading it from server.
Problem seems to have resolved on its own with Firefox 52 by the way. You can still trigger a memory leak if you are refreshing the browser too much in short amounts of time or rapid scene changing in very short periods of time though. The browser will almost always clear memory as necessary now. It’s completely workable for what I have going on at least.
I am using 65.0 64 bit firefox version and using unity 2018.3.8 deployed webgl build but the problem is still the same,
it is incrementing the memory when i refresh the page. How did you solve that? I am getting wasm: out of memory error
in Firefox while aw snap error in chrome. surprisingly chrome don’t show memory increment in its task manager but crash with aw snap error.
Thanks for your reply but certainly this is not the solution. why it occurring? even reloading the empty scene producing this result. This is really disturbing, unity should need to solve it.
I have very large project which i have divided in asset bundle but it seems that it is not feasible in unity.
If I remember it correctly, I was getting the same problem in chrome and firefox. Each time i reload the page it double the memeory. So it found that if your devTools are open while you are reloading in chrome it will double the memory but if you close the devTools in chrome then it will work fine. Whereas for the FireFox it is not true. It will double the memory no matter the devTools are open or closed. Each Reload/refresh will dobule the memory. Here are some helpful links for you Main link & 1