I am developing a card game. I received the following warning from Xcode:
Received memory warning… WARNING → applicationDidReceiveMemoryWarning()
When the game changes scene from Main Menu to the Game Level, it crashes. It doesn’t happen in all phones of the same model though ( tried with different iPhone 5 devices, I get the message in some of them).
When you say crash do you mean that the OS is simply killing your app, or is an actual crash (which may have nothing to do with memory usage)?
I’m no expert but you you could try using the Xcode tools to track memory usage, or use the Unity memory profiler. You could try unloading unused assets?
yeah OS kills the app. I think unloading unsused assets will do it right? I mean why it crashes on some devices and others not? ( taking into consideration they are the same device type)
Memory warning happens when iOS detect that it runs low on memory. It informs applications that if no one clean his s**t, it will starts to kill apps to free up some memory.
Why it happens on some devices and not on others that have the same hardware? Because every phone is different. Each user installs his own apps, some user install apps with low memory footprint. But other install big apps with high memory footprint.
iOS can choose to kill your app or not, he choose one app that take lots of memory and kill it, even if it’s currently running.
So you better clean your garbages if you don’t want iOS to be your mother and clean your garbage in a very angry style ahah
We have made some nice discovers recently about memory.
We found that any prefab linked in the scene(even if you never load it), loads everything it contains in memory. It includes textures. If you have a prefab with many textures, it will load textures into memory.
If you instantiate the prefab, you will still all in memory.
Now, if you replace your prefabs with a local AssetBundle system, objects will be loaded in memory only when you instantiate them, and will be destroyed when you destroy your GameObject.
We reduced the memory load with that. (on Main Screen of our game, before: 40K object in memory, after: 19K /// Before: 140Mb of Texture, after= 100Mb of Texture).
Remember to compress your textures.
For big atlases with alpha, we used a shader that combine a RGB atlas with a copy of our atlas in Alpha 8 format.
A 16Mb 2Kx2K atlas now weight 6Mb(Atlas+Alpha Mask), before, it was 16Mb with no compression.
Definitely, if you make these 2 things, will be able to perfectly control what is in memory and what is not in memory, and remove from memory useless objects when you know that your memory footprint is high.