Hi there,
I noticed some Render Textures not being freed when leaving the game scene to, for example, a simple main screen. One of them has to do with the shadow atlas cascade and others about post-processing stuff.
I use Unity 2019.4.6 and HDRP 7.4.1.
Please see image attached from memory profiler. Diff was made using main screen captured before and after game screen. I sorted the “New” group by bigger size.
Any help is more than welcome. Thank you.
Sergi
That’s expected behavior unless you are calling Resources.UnloadUnusedAssets after the previous scene has been unloaded or you loaded an empty scene in between. Assets used in a scene are kept in memory as the scene is unloaded until the next scene after is unloaded, just in case the scene you load after you unload the first one shares the needs for some resources and Unity would otherwise spend too much time needlessly loading and unloading them.
They have a ref count of 0 so they will be unloaded the next time UnloadUnusedAssets triggers, either because you call it or because a scene is unloaded.
Hi Martin,
Thank you for your answer.
Yeah, I realized that after a few more captures those references were gone but my memory (task manager) keeps accumulating large chunks of mb (20-30) each time I go from game scene to main menu.
There is a loading screen in between that I unload, as the next scene is loaded async, but I can’t find where the issue comes from. Is is possible to send a log/capture or something from the memory profiler so you maybe could take a quick look? That would help a lot to point out the issue.
Thanks again,
Sergi
The two scene unloads needed to be non-async (or passing an optional book to unload assets) to trigger Resources.UnloadUnusedAssets. you could also just call it your self in that loading scene to be sure.
You might want to look into the MemoryMap in diff view to find what’s different. Maybe it isn’t object related but due to Memory pools or heaps expanding?
Not usually no, unless it’s a bug with the Engine, then as a bug report. Also I’m technically on vacation right now
Thank you Martin. I will take a look. Enjoy your Holidays!
Sergi
1 Like