Hi folks,
I’m currently trying to track down a pretty epic memory leak that eventually, after a pretty short session, causes the webplayer to crash with the delightful “Too Many Heap Sections” error.
I’ve been trawling around the Unity forums for about a month now trying almost everything. We’ve recently updated from 3.4 to 3.5.5 (the issue was occuring before the update btw) and the profiler is definitely a lot better and I have some observations but also some confusion about the numbers returned.
I have been switching between our lobby and football match scene and generally in task manager the memory usage climbs and climbs, the profile when attached to the webplayer however displays a different story.
Task Manager
Iteration 1
Lobby: 520MB
Match: 640MB
Iteration 2
Lobby: 660MB
Match: 740MB
Iteration 3:
Lobby: 760MB
Match: 790MB
Iteration 4:
Lobby: 860MB
Match: 840MB
Profiler:
Iteration 1:
Lobby: 125MB
Match: 190MB
Iteration 2:
Lobby: 132MB
Match: 192MB
Iteration 3:
Lobby: 135MB
Match: 192MB
Iteration 4:
Lobby: 135MB
Match: 192MB
So the profiler looks to be pretty stable but the task manager has the RAM usage just running away. Eventually it goes over 1GB+ and crashes and burns.
Our usage of memory in general has not been wise, we have a few thousand lines of code and objects are being newed up liberally, even in updates and ongui calls. Also the string manipulation is a pretty hap-hazard, given the reams of code we have, I don’t think I’ll be able to fix all of that at the moment. However the core of this stuff has been in place for some time and not caused problems before. This worries me but still I don’t think it could account for the massive jumps in RAM that I’m seeing.
In between scenes we change to an empty memory dump scene and manually call Resources.UnloadUnusedAssets() along with System.GC.Collect(0, System.GCCollectionMode.Forced) and System.GC.WaitForPendingFinalizers(), the game doesn’t seem to be hanging onto resources from what I can see, at least the profiler figures don’t seem to say that it is.
I’ve been using the handy DetectLeaks.cs script to track down what skins/gameobjects are currently loaded to verify that we don’t have a ton of unexpected stuff in place.
Anyone got any suggestions on how to tackle this further? I know its tough without any source but wondering if any other people out there might have had similar experiences?
Appreciate any help.