views:

1540

answers:

2

Need advice on how to debug this. I'm new with limited environments and have no previous embedded or smart phone programming experience so I could use some clues. Already aware of: Instruments, Clanger Static Analysis, manual code review, etc. Instruments seems to be very helpful in general but quite time consuming and freezes up a lot of the time! Clanger has also helped me a lot as well. It seems like I'm just consuming too much memory in general and I'm wondering what a good strategy is. Do I release some top-level objects? Is there a 'preferred strategy'?

Just wondering if anyone has tackled this successfully and if they have any other suggestions? Thanks all.

+2  A: 

Basically you're receiving this warning because (unsurprisingly) the iPhone is dangerously low on memory. This can generally be for one of two reasons;

  1. You have a memory leak.
  2. You are allocating far too many objects and need to revisit your design.

For the first one you should run instruments and examine your memory allocations. This can really slow down your app (and requires additional memory) so try testing areas of your app one at a time. E.g. if you have multiple views switch between them a couple of times.

For the second you will have to examine things you are doing that could result in large memory allocations. For example if you're writing a Flickr browser you might need to cut down the number of images you have loaded at anyone time, or free up some unused ones when you receive this warning.

These are about the only general rules I can suggest without knowing more about your app.

Unfortunately there's no real way (that I know of) to get figures for current memory allocation from the iPhone OS. This makes it really difficult to isolate the areas of your application that are inadvertently memory hungry.

Andrew Grant
3. You are having to deal with network xml / images / data that cannot be loaded all into memory at once (like a desktop) and must be dealt with in smaller pieces
slf
In terms of ideas for a better design, the SQLite Books example in the Apple document describes one strategy of hydration/dehydration. The readme provides an excellent explanation of the concept and has data objects that implement this pattern.
hyuan
+2  A: 

There are a lot of good articles for memory management in an iPhone app. Here are some useful links.

http://iphonedevelopertips.com/objective-c/memory-management.html

http://kosmaczewski.net/2009/01/28/10-iphone-memory-management-tips/

http://cocoa-touch.blogspot.com/2008/09/memory-management-on-iphone.html

Things you should in general take care of

  1. Release any variables which you do not need
  2. Always handle didReceiveMemoryWarning and release any variables not in use
  3. Stop any memory-heavy processes in applicationDidReceiveMemoryWarning like audio/video playing, UIImagePickerController etc
  4. Do NOT use imageNamed: to create UIImage objects.
lostInTransit