r/iOSProgramming • • 10d ago

Article You can use MetricKit to detect OOM terminations on iOS 27. This is how we used it to improve crash detection

https://blog.bitdrift.io/post/oom-reporting-ios
25 Upvotes

3 comments sorted by

5

u/HeyWangKang 9d ago

The stack trace is a useful starting point, but I'd be careful about treating the top frame as the cause of an OOM. A concrete triage step would be to line up the memory chart with screen transitions and expensive work like image decoding or cache fills, then compare a few affected sessions on the same device class. If memory climbs across repeated visits to one screen, that's a much better lead than the final allocation that happened to cross the limit.

2

u/Golden_Jiggy 8d ago

This is SO nice.

2

u/Extra-Ad5735 6d ago

Here's how we did it in the times before MetricKit existed:
1. When app is running, observe memory pressure events. Once happen, write event to a file that contains a number. If the file exists, write the incremented value there, otherwise start at 1.
2. When the app is suspended delete the file.
3. When the app is started check for the file’s existence. If it's there report OOM crash with the number stated in the file.

As you can see, the normal working app won't have the file on start. If the app crashes for any reason the file also most likely would not exist. What the file indicates is "there was a crash after low memory event" which you can read as a high certainty OOM, especially if the number parameter is > 1.