Memory leaks iOS

Hello everyone,

we are developing a game on iOS and we run into some very strange issues with memory. Lets say we load a Scene A and in memory we could see we have Material 1 and Texture 1. Now we load the Scene B and return to Scene A. Now we can see that we have Material 1 and Texture 1 but also Material 2 and Texture 2 form the scene B. This is a very simplified explanation. Not every asset is transferred into Scene A from Scene B, just few of them. I know that you are now probably thinking that we have some reference to these objects or they are static but they are NOT. In every scene few assets are transferred completely random it seems. The memory of our application is rising and after few scenes it will crash. Does anyone has a same problem? Ressources.UnloadUnusedAsstes does nothing. What we do now is manually unloading assets via Resources.UnloadAsset(asset). But this is very cumbersome solution. Anyone has a same experience? We are using Resources.FindObjectsOfTypeAll(Type) to know which assets are loaded into the memory.

Have you tried loading an empty scene between scenes to flush everything out?

Yes I tried. Nothing is flushed actually

how can u see that in memory?

i have had memory leak in my game (crash when laoding a new level) and i used an empty scene with a C# script to load what i want after everything is unload.

but, i have no idea how to cheack memory so i dont know if my method really works, i only know that it loads and xcode instruments show me nothing wrong.

As I wrote above. We use Resources.FindObjectsOfTypeAll(Type) method to see all objects loaded into the memory. So no one having a same issue? Everyone comfortable with loading empty scene and ALL memory is freed as expected?

well, if you can create very simple repro (like the scenario you mentioned) then bug report it - this way it will be way faster to find the solution (i saw plenty of times when users found the problem while trying to create small repro ;-), on the other hand if you manage to do it - it will be fixed really quick, as we wont need to dig through tons of stuff)

Just to make things clear. Is a standard behavior that when I load an empty scene , all assets and gameobjects that has no reference should be cleared out of memory? So calling Resources.FindObjectsOfTypeAll(Type) method should return 0 assets for a given type? Because when I load an empty scene I can see hundreds of Textures,Materials and thousands of Gameobjects when I call Resources.FindObjectsOfTypeAll(Type). And the memory corresponds, nothing is freed.

Well, not quite zero (as we have, for example, builtin shaders and textures) but generally you are not far from truth 8)
I would say that was i expected is like that:
let’s say you just loaded scene A. you check the memory/objects - it is baseline. If you then load scene B and then scene A again - you should be back (or close to) baseline.
At least that’s the impression i have ;-). If you can create small repro saying the opposite - bug report it we will check

Hi, just to reply to my old thread. We find out that the problem with memory leaks has to do with the “forgotten” references to our objects/singletons. As we use a lot of 3rd party plugins it is often also caused by the authors as not everyone know about GC management on iOS. So even destroying, unloading every single assets wont help as it is described here (http://forum.unity3d.com/threads/77996-Mono-Memory-Garbage-Collections-apparently-not-working-on-the-device). Our game will after few hours of gameplay simply crash due the memory leaks. It would be very hard for us to track all the refernces which are not freed and free them manually so we are now looking for an another solution.
It there a way to “restart” unity and run it again via code? Or is it possible to run “unity within unity” and then just destroy it and free all the memory? We just need to somehow find a way to force GC to free all the memory on the heap. Launching empty scene and unloading/destroying all assets will not help as the memory is lingering dead in forgotten references to our singletons/objects. Anyone has any idea?