views:

73

answers:

2

I have an app that often crashes on the device (iPad), but not on the simulator, so any simulator debug tactics (MallocStackLogging for example) are not an option. What I usually get in the console is this:

Received memory warning. Level=1
Received memory warning. Level=2
Program received signal:  “0”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")

My question is, at this point, is there something I can do to find out exactly what is causing the crash? Obviously it's a memory issue, but I'm having a hard time finding the cause. Is it a leak? Too much allocation? Is there anything besides "Run with Performance Tool > Leaks" that I can do to track down the problem?

+1  A: 

Use Instruments to see where all your memory is going.

I'd start with Run with Performance Tool -> Allocations.

Also, I find Leaks to be pretty conservative. I haven't seen a single false-positive from Leaks, but I've found plenty of leaks that Leaks didn't detect.

Jon-Eric
So what am I looking for in Allocations? It crashed with these stats: Live Bytes: 23.13 MB, #Living: 85455, #Transitory: 3856520, Overall Bytes: 475.43 MB, Overall: 3941975. Are any of those bad? Seems like it was hovering around 24-25MB of Live Bytes without crashing for a while.
sol
First, make sure you're doing this in *Release on the device*. Watch *Live Bytes*. 25MB is pretty close to the maximum. You might want to drill down and find what's using all that memory.
Jon-Eric
Why would I receive a low memory warning when Live bytes is only around 10 MB? I can tell that I'm getting the warning because viewDidUnload gets called on some view controllers.
sol
You get a warning when the *device* runs low on memory. In iOS 4 it might be that other applications are still using memory. Or that your application has (indirectly) gotten the OS to cache some items (images). I wouldn't worry about *just* warnings if your application isn't ejected. When it *is* ejected, you'll get a Low Memory crash log which tells you how many pages (4K each) your app was really using.
Jon-Eric
+3  A: 

Another good tool is the Static Analyzer. Just click Build and Analyze in the Build menu and it will show you somewhere between many and most of your memory leaks.

Check out the Apple Developer Document for more explanation on how to read the results.

MattLeff