Hi all,
I am trying to track down a memory related crash in my project. After seeing enough crash reports, I believe the memory leak happens on my scene changes.
I used the memory profile tool, changed scenes a few times, and started digging into the results.
I am now quite confused as to what is going on.
It appears as though none of my class allocations are ever being garbage collected.
For example, if I look at this ‘Game’ class.
- 1 of these should be created in a scene; max.
- There should be no global / static references to it.
- It should be (eventually) GCed after changing to the next scene.
This snap shot was taken after running through 3 scenes, and then moving into a blank, empty scene.
However, there are 3 instances still floating around in memory.
The reference info is quite confusing as well.
- The middle pane shows that each Game class instance has about 160 ish references. That seems logical as a scene is running. There are many other classes within the scene that store pointers to it.
- However, I would expect this all to get cleaned up after the scene is dumped.
- The right inspector, however, shows 0 references. And that is true for each of the 3 Game class instances. I am not sure which is correct.
This same pattern is true for every class I have looked into. I have not found a single class (monobehaviours, scriptables, basic allocated classes, etc) that is not still referenced and in these snapshots.
Is this info wrong? Is this an issue with the Memory Profiler? I don’t think this is the case, because I have real crash logs showing a memory leak in my project.
I thought I understood C# and how the GC works, but maybe I am totally wrong? I thought that everything should be cleaned up once the scene is dumped; so long as there are no more references to anything.
Any help here would be greatly appreciated.
Thank you for your time
Les