Daily iOS
Performance and debugging

Large image pipeline

An iOS feature that edits and saves photos of tens of MB gets killed after a memory warning. From decoding to saving, how would you lower the memory peak?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Instead of decoding the original whole into a UIImage, downsample at decode time with ImageIO's CGImageSourceCreateThumbnailAtIndex to only the size the screen and the edit need, release each stage's intermediate buffers right away with autoreleasepool and short scopes, and for the final save stream the original from disk and process only the region you need.

Share a question