- Home /
Issues with unloading textures and atlases
We seem to be having some issues with Unity not unloading textures (and other assets) that are no longer in use. During the development of a previous project in Unity 4.x, I created a tool that reports the amount of textures, meshes, materials, sounds, etc., using the Resources.FindObjectsOfTypeAll method. This tool seemed to work nicely in Unity 4 and helped us track down memory leaks in our previous project. I hope this method still works as it did back then? We are now in Unity 5.2.4.
To explain in a bit more detail what is going on, our game loads new scenes by first fading out, showing a load screen and then 'behind the curtains' load an empty scene, in which we call Resources.UnloadUnusedAssets () and System.GC.Collect (). After this the game loads the actual scene that was requested. The problem is that it seems unused assets are not being unloaded in this process. We have a main menu scene with some buildings in it, but upon loading any of the actual gameplay scenes, the meshes and textures used on the buildings in the main menu scene are still loaded, at least according to FindObjectsOfTypeAll. Same issue when we return to the main menu after having been in any of the gameplay scenes: A lot of the assets used in the gameplay scene are still reported as being loaded.
I know that if just one object somewhere references a prefab or is linked to a texture or anything like that, the asset will remain in memory, but I can't find anything in our gameplay scenes that should be referencing assets from our main menu. It might be that we are, but I just can't find it, so I'd like to confirm that this is not a known issue with Unity 5.x.
Another thing is that according to the tool I made, it seems that various texture atlases, created with Unity's SpritePacker, are loaded multiple times. My tool looks through the loaded assets and counts assets with the same name and some of the sprite atlases (textures starting with 'SpriteAtlasTexture') seem to be appearing multiple times in the list. Is there a reason for that? It also seem to load texture atlases that aren't used.
Your answer
Follow this Question
Related Questions
Can we unload NavMesh in runtime? 0 Answers
Loading a Random Resource in a Folder Without Using Resources.LoadAll 0 Answers
Question about asset memory not freed after calling SceneManager.UnloadSceneAsync() 0 Answers
Memory problem. How do I dump a Streaming Asset from memory? 1 Answer
Unable to free resources from memory 0 Answers