I've got a notification service extension with quite a lot going on, and consequently I've been running out of memory.
One thing in particular that is using a lot of memory is UIGraphicsImageRenderer which I'm using to construct an image at run time the size of the device's bounds.
Running the extension in Xcode and profiling its memory it appears that using autoreleasepool {} doesn't seem to always release memory instantly, so if you do A and then B, and combined they have too much memory usage for the extension to handle, trying to autorelease A doesn't actually always release the memory before B (unlike if the code is running in the main app rather than an extension).
A few questions
- is there any way of programmatically detecting the memory usage / memory limit within the extension?
- if the extension goes over the 24Mg limit, is there any way of catching that exception and handling it somehow?
- is there a way of ensuring/forcing autoreleasepool{} to clear memory before proceeding with further code?