5

I have an action extension which takes in an image, makes a small modification to the image (such as overlay a watermark), then allows to the user to open another UIActivityController to send the modified image to another (arbitrary) extension (such as to share the image to social media). My extension crashes after sharing to most (but not all) extensions, due to hitting a memory limit.

The error I get is:

EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=120 MB, unused=0x0)

This happens deep within an OS-driven UIImage call.

Steps:

  1. Select an image from the Photos app
  2. Select the Share icon
  3. Select my extension
  4. See the modified image within my extension
  5. Select the Share icon
  6. Select some other extension (Tweetbot, Facebook...)
  7. See the UI for the other extension begin to appear
  8. Crash

The crash does not appear for iOS-provided extensions such as saving or printing. The crash does appear for all third-party extensions I've tried.

I used Instruments to diagnose. My extension's memory usage briefly peaks at 75MB while doing image operations, then settles down to 27MB. When the UI begins building for the other extension, my app's memory footprint quickly skyrockets. It hits 120MB, then dies.

I get three didReceiveMemoryWarning calls during the memory escalation. The only data I'm holding is the on-screen UIImageView. I've tried killing that UIImageView at this point (imageView.removeFromSuperview then imageView=nil) with no change in result.

It appears that the secondary extension is loading in my extension's memory, and the combined footprint exceeds the 120MB limit. Does that make sense? Is that expected?

I'll admit the idea of an extension that exists just to temporarily hold data to be shared to another extension might not be common, but it's the best approach I can think of. The modified data doesn't need to be saved permanently - and might be easily confused by the user if the new version was also in their Photos library. I've thought about my extension opening my main app to share from there, but that seems to be prevented by design (with some hacks suggested that I haven't tried - see openURL not work in Action Extension).

Any workaround ideas? Thanks!

Mitch Cohen
  • 1,551
  • 3
  • 15
  • 29
  • For what it's worth, I got rid of my UIImageView for testing. Usage dropped another 15MB but still kicked the 120MB limit on sharing. – Mitch Cohen Dec 26 '18 at 23:28
  • Have (almost) the exact same problem. An action extension grabs a photo, adds an overlay, and saves it to an album. Of course with no hard memory limit my parent app works, but the extension crashes with this same error when the image exceeds !8mb. It fails in a drawInRect with vImage`_ERROR_Buffer_Write__Too_Small_For_Arguments_To_vImage__CheckBacktrace: Did you ever find a solution? – user1139479 Apr 01 '19 at 13:38

0 Answers0