IOS4 - quick context switching

When the application enters the background working state, how many dirty memory applications are good to go. In an apple video, he mentioned that dirty memory should be reduced as much as possible.

But in my application, I use a navigation controller to show and view pop. After moving from about 20 different pages, the use of dirty memory reaches 30 MB or so.

Also, on "rejectModalViewControllerAnimated" and "popViewControllerAnimated" dealloc is not called.

I have two doubts:

  • How acceptable is the amount of dirty memory for life?
  • What is an alternative to the navigation controller to support the back button?

Thanks in advance.

+6
iphone ios4
source share
2 answers

You can still have your UIViewControllers if dealloc is not called.

Perhaps you are setting delegates or other classes to these UIViewControllers that are persisted and referenced by the tree backup (circular links).

The way you can debug this is to overload the save and release in your UIViewController and set a breakpoint and log keepCount.

Here is a magical fragment that I leave running, which helps me a ton when I can’t understand why I'm still saving something.

- (id)retain { NSLog(@"retain \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]); return [super retain]; } - (void)release { NSLog(@"release \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]); [super release]; } - (id)autorelease { NSLog(@"autorelease \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]); return [super autorelease]; } 

__PRETTY_FUNCTION__ is a special hidden macro in CLang that gives the beautiful name of the Objective-C function as a char array.

+4
source share
  • When iOS runs out of memory, it tries to kill background processes that use most of the memory. Therefore, as long as there is no absolute good amount, minimizing how much memory you use is a good idea. Leaving it at 30 MB is equivalent to killing your application.
  • If you do not want to change your interface, there is no need to use anything else that the UINavigationController to work with your button. I think the problem here is that if dealloc not called in pop or firing, you have a memory leak

Almost all view controllers have data that is effectively cached and can be recovered when the application returns to the forefront. Think about the data that you publish when you receive a memory warning when you start the application. (You respond to memory warnings, right?) This is what should be released when you go into the background.

0
source share

All Articles