How to deal with low memory warnings on the iPhone?

I'm having problems with my application receiving low memory warnings while the user is deep within a navigation controller stack of views. After the user browses through a bunch of hierarchical options in subsequent UITableViews, he can open a PDF document in a UIWebView (in a different view controller).

Everything works fine, the PDF loads and the user can flip through the pages. However, when the document is a bit large, or has several pages, and the user taps on the "Back" button in the navigation controller, he app crashes as the previous view controller in the navigation controller stack has been deallocated.

After searching around for ways to deal with low memory warnings, and dealing with this type of problem, I found several posts that just advise people to release the objects that can be released, and then lazy-load them later on when the user tries to load a view that has been deallocated. One of these posts is Craig Hockenberry's Dealing with memory loss: the cleanup post.

While that's a bit helpful, it doesn't give me much information to work from.

Can someone provide a simple guide on how to deal with low memory warnings, and how to implement "lazy loading" of objects?

Answers


When memory is low, the system sends out a series of memory-related messages. Any instantiated view controllers will get the -didReceiveMemoryWarning message. If you don't implement this, the default action (assuming the view controller is not front-most) is to release the controller's view member. If you've got hooks into it, or perhaps into its subviews, that could cause issues when your controller gets returned to the top of the stack.


Need Your Help

could not deduce template argument in VS 2010

c++ visual-studio-2010

In VS 2005 this code work fine, but in VS 2010 I have error

Angular e2e tests affecting database

angularjs testing webdriver protractor angularjs-e2e

Here's my issue, steb by step :)) I thought it reads better this way, unlike a wall of text pitifully trying to explain my very domain-specific problem.