4

The Info

I recently launched an app on the AppStore. After testing on the simulator thousands of times, and actual devices hundreds of times we finally released our app.

The Problem

Reviews started popping up about app crashes when the user launches the app. We figured that the app crashes on launch on iOS devices with less than (or equal to) 256 Mb of RAM. The following devices are devices our app supports with less than 256:

  • iPod Touch 4G
  • iPhone 3GS
  • iPad 1

The app doesn't always crash. Sometimes it launches fine and runs smoothly. Other times it crashes. The time from launch (when the user taps the icon) to crash is usually two seconds, which would mean that the system isn't shutting it down.

Findings

When using Instruments to test on certain devices, I find the following:

  1. There are no memory leaks (I'm using ARC), but there are memory warnings
  2. Items are being allocated like crazy. There are so many allocated items, and even though I'm using ARC it's as if ARC isn't doing what it's supposed to be doing
  3. Because of what I see as "over-allocation", the result is:

    This app takes (on average) 60 MB of Real Memory and 166 MB of Virtual. When the app launches the memory being used quickly increases until it reaches about 60 MB at which point the view has been loaded. Here is a snapshot of the Activity Monitor in Instruments: enter image description here

I know that those figures are WAYY to high (although the CPU % never really gets up there). I am worried that ARC is not working properly, or the more likely case: I'm not allocating objects correctly. What could possibly be happening?

The Code and Warnings

In Xcode, there are only a few warnings, none of which pertain to the app launch or any files associated with the launching of the app. I placed breakpoints in both the App Delegate and my viewDidLoad method to check and see if the crash occurred there - it didn't.

More Background Info

Also, Xcode never generates any errors or messages in the debugger. There are also no crash reports in iTunes Connect, it just says, "Too few reports have been submitted for a report to be shown." I've added crash reporting to my app, but I haven't released that version.

A Few Questions

I started using Obj-C just as ARC arrived, so I'm new to dealing with memory, allocation, etc. (that is probably obvious) but I'd like to know a few things: How can I use @autoreleasepool to reduce my memory impact? What do I do with memory warnings, what do I write in the didRecieveMemoryWarning since I'm using ARC? Would removing NSLog statements help speed things up?

And the most important question:

Why does my app take up so much memory and how can I reduce my whopping 60 MB footprint?

I'd really appreciate any help! Thanks in advance!

EDIT: After testing on the iPhone 4 (A4), we noticed that the app doesn't crash when run whereas on devices with less than 256 MB of RAM it does.

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
  • haven't you got access to a crash log from the device? – sergio Jul 04 '12 at 15:20
  • @sergio no crash logs in iTunesConnect: "To few reports submitted for a report to be shown" – Sam Spencer Jul 04 '12 at 15:22
  • 1
    It's really helpful to add a crash reporter to your app for exactly these reasons. My experience: http://www.zx81.org.uk/computing/opinion/why-you-need-a-crash-reporter.html – Stephen Darlington Jul 04 '12 at 15:28
  • @StephenDarlington so is there about nothing I can do but try to guess the problem (until I update with the crash reporter)? – Sam Spencer Jul 04 '12 at 15:39
  • @RazorSharp Knowing _when_ it crashes has been enough for me to figure the problem in some cases. But if you can't, I'm not sure there's much you can do short of acquiring a A4-based device. – Stephen Darlington Jul 04 '12 at 15:59

1 Answers1

6

I finally solved the issue. I spent a few hours pondering why my application could possibly take up more RAM than Angry Birds or Doodle Jump. That just didn't make sense, because my app does no CALayer Drawing, or complex Open GL Graphics Rendering, or heavy web connection.

I found this slideshow while searching for answers and slide 17 listed the ways to reduce memory footprint. One thing that stuck out was PNGCrush (Graphics Compression).

My app contains a lot of custom graphics (PNG files), but I hadn't thought of them affecting my app in any way, apparently images (when not optimized properly) severely increase an applications memory footprint.

After installing PNGCrush and using it on a particularly large image (3.2 MB) and then deleting a few unused images I ended up reducing my apps memory footprint from 60+ MB and severe lag to 35 MB and no lag. That took a whopping five minutes.

I haven't finished "crushing" all my images, but when I do I'll update everyone on the final memory footprint.

For all those interested, here is a link to a blog that explains how to install PNGCrush (it's rather complicated).

UPDATE: Instead of using the PNGCrush process (which is very helpful, although time consuming with lots of images) I now use a program called ImageOptim that provides a GUI for multiple scripts like PNGCrush. Heres a short description:

ImageOptim seamlessly integrates various optimisation tools: PNGOUT, AdvPNG, PNGCrush, extended OptiPNG, JpegOptim, jpegrescan, jpegtran, and Gifsicle.

Here's a link to the website with a free download for OS X 10.6 - 10.8. Note, I am not a developer, publisher or advertiser of this software.

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133