0

How to be alerted of memory warnings? Unity3D, building to Android.

Cheers.

Fattie
  • 27,874
  • 70
  • 431
  • 719

2 Answers2

2

You can subscribe to Application.lowMemory Documentation

For example, in some monoBehaviour starting your game:

private void Start() 
{
    Application.lowMemory += ReportSystemLowMemory;
} 


private void ReportSystemLowMemory() 
{
    Debug.LogWarning("Warning: Low memory");
}
  • Be sure to don't subscribe ReportSystemLowMemory more than once.
  • Also unsubscribing it would be a good practice, ie Application.lowMemory -= ReportSystemLowMemory when you are close your app/game.
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
mayo
  • 3,845
  • 1
  • 32
  • 42
0

There is no inbuilt function for this in Android as far as I know.

meredrica
  • 2,563
  • 1
  • 21
  • 24
  • I see - to be clear, you mean, unrelated to Unity. There is - simply - no memory warning concept in Android? Is that right? Thanks so much BTW. – Fattie Mar 25 '14 at 20:03
  • Wait - what about onTrimMemory and onLowMemory ? Eg http://stackoverflow.com/questions/14767766/android-counterpart-of-ios-memory-warning – Fattie Mar 25 '14 at 20:04
  • Those methods are not called prior to an OOM exception. They are called when the overall system is low on memory. – meredrica Mar 27 '14 at 10:47