How do I catch a low memory warning from iphone in Unity?
I have created an app on both android and ios, but I keep experiencing random crashes only on my iphone device. Upon debugging in xCode, I realised that every time before the crashes happen, there are several memory warnings thrown.
WARNING -> applicationDidReceiveMemoryWarning()
I figured I had to unload all my unused assets in the event where my memory is running low, but is there any way in which I can catch this warning and handle it in Unity?
I have seen answers which required the developer to make plugins in other languages such as objective C, or C with code snippets, but I have no knowledge in objective C or how to make plugins for Unity, so are there any solutions which I can use in Unity?
Answer by UnityCoach · Jul 11, 2017 at 09:36 AM
If there's such a plug-in already available, you'll find it in Prime31 plugins.
Now, from my experience, when you receive this message, it's most of time too late unfortunately. By the time you free memory after receiving a warning, you'll have received another message that says something like "application will close, last call for saving data".
That's why profiling on these platforms is so important.
It is still useful info to get though, you can log it in metrics, along with device type. e.g. with $$anonymous$$ochava or UNity$$anonymous$$etrics. Its impractical to have all devices to profile and test on before launch.