I have a memory problem in iOS because I’m loading some sprites from an asset bundle that I than store in a list to use as a sprite animation. After I don’t need them, I just clear my list, and call Resources.UnloadUnusedAssets. The problem is that when I want to run another set of animation, it will eventually crash because it ran out of memory. Am I not doing the right thing ? Do I have to destroy to sprites or just clearing my list and then calling the method should do it ? Do I have to wait a frame for the GC to collect the sprites or something. Any ideas ?
Hey there I’m working on a similar system at the moment. What mine does is stream texture2Ds from an asset bundle.
The textures won’t unload until you release every reference, call Resources.UnloadUnusedAssets, and then allow the garbage collector to do it’s thing.
Most of the time these kinds of memory issue are due to references you don’t know about.
In order to track down your references I’d recommend using the memory profiler. Switch it to detailed mode and it will show you how many references to each texture it has.
Here is my process:
Load an asset bundle.
Load a texture2D from the asset bundle.
Create a sprite from this texture2D.
Display the sprite.
When it’s done call Destroy() on the Sprite.
set your reference to that Sprite to null.
It’s also a good idea to react to memory warnings on iOS. I inserted some code into the didReceiveMemoryWarning delegate that calls UnloadUnusedAssets.