views:

307

answers:

2

Hi all,

I have a quick inquiry regarding how and when didReceiveMemoryWarning gets invoked. I completely understand how to properly use the method. My question that I cannot find in documentation however, is whether or not it is my fault for the way I'm managing my memory footprint for this method being invoked?

Is it possible that I'm doing everything perfectly fine and that the iPhone OS needs memory, thus sends me this notification since I'm a third party app? I've been running leaks, ObjectAlloc and whatever tools I have available in order to see any odd behavior. My memory footprint peaks at 2.2MB at most. I don't see anything particularly horrible being done code wise.

Now it's getting to the point where I'll have some other apps open, use my iPhone here and there -- then open the app I'm developing. This view is a UITableViewController ultimately that displays a dataSource that was built from a remote XML feed. So it is possible that I'm doing something terribly wrong. But I need to understand this method better before making any accusations on my own code.

Is it possible for this method to be invoked on an app that's perfectly healthy in how it manages memory?

+1  A: 

Memory warnings can happen at any time. There are apps running in the background, like Mail and Safari, doing who-knows-what.

Chris Lundie
+1  A: 

In many ways it doesn't matter who is responsible. Apple's code does leak; especially the image picker and the HTTP classes (although the latter do not leak badly). Whatever is causing the warning, you are the only person who can write code to recover from it.

There is no documented memory footprint (I'm aware of) for an app so I think that it is certainly possible for this message to be sent to an app at any time. It is certainly sent at different times on the simulator and the phone. This means that there is no "safe footprint" under which you can guarantee never to receive a memory warning. Obviously keeping your memory footprint low makes it less likely.

Maybe you should post some sample code to see if it leaks a lot. The app you describe sounds simple enough that it shouldn't cause a memory warning in normal use.

Roger Nolan