How can I address an app that started earlier, but is "Terminated due to Memory Pressure" now?

22,481

Review the Performance Tuning section of Apple's iOS Programming documentation. Use Apple's Instruments application to determine how, when, and how much memory your app is using.

One approach you should consider is to disconnect the graphics resources from your application, and add them back one-by-one once you feel they meet the requirements and limitations of iOS.

Now, this part of my answer is opinion: it sounds like your app is a high risk for being rejected from the App Store, in case that is your intended destination for this app.

Share:
22,481
Christos Hayward
Author by

Christos Hayward

Jonathan Hayward is a recovering geek. He holds master's degrees bridging math and computer science (UIUC) and philosophy and theology (Cambridge), and is considered to be in the profoundly gifted range. He is presently learning Node and Russian. Read full biography—it's interesting.

Updated on May 09, 2020

Comments

  • Christos Hayward
    Christos Hayward almost 4 years

    I am working on an iOS app in Xcode. Earlier I got it to start and run, up to a limited level of functionality. Then there were compilation failures claiming untouched boilerplate generated code had syntax errors. Copying the source code into a new project gets a different problem.

    Right now, I can compile and start running, but it states before even the launch image shows up that the application was closed due to memory pressure. The total visual assets is around 272M, which could be optimized some without hurting graphical richness, and is so far the only area of the program expected to be large. (The assets may or may not be kept in memory; for instance every current loading image is populated and my code never accesses any loading image programmatically.) And it crashes before the loading image has itself loaded.

    How can I address this memory issue? I may be able to slim down the way images are handled, but I suspect there is another root cause. Or is this excessive memory consumption?

    Thanks,

  • JRG-Developer
    JRG-Developer over 10 years
    +1: I agree, this will likely have trouble making it through the app store review if you're using so much memory on initial launch... you've gotta optimize this.
  • Christos Hayward
    Christos Hayward over 10 years
    Thank you. I know at least one optimization that should significantly cut the total launch images... but a large portion of the size is launch images.
  • bneely
    bneely over 10 years
    A quick tip on images is: resize the images so they are the maximum size that iOS would use (for example, if you have a 600x600 image on disk but only display it as 300x300 on a retina display, resize the source image to 300x300).
  • Christos Hayward
    Christos Hayward over 10 years
    I have been creating images sized for the maximum that would be used. For portrait and landscape loading and background images on an iPad using Retina, that's still a lot of weight. Or are loading and background image only loaded as needed or as called for by code?
  • bneely
    bneely over 10 years
    It depends on your code. You need to avoid caching UIImage objects because they consume a lot of memory. Make sure you load images from the filesystem only when they are needed.
  • Christos Hayward
    Christos Hayward over 10 years
    Note: When it was running, memory usage was around 4M. 272M was a total size for assets in the bundle including launch images and backgrounds, not something I was lazily loading.