Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS4 - fast context switching

When application enters in background running state, how much dirty memory usages is good to go. In apple video it's mentioned that the dirty memory should be reduced as much as we can.

But in my App, I am using navigation controller to push and pop views. After moving from about 20 different pages, the dirty memory usages reaches 30 MB or so.

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

I have two doubts:

  1. With how much dirty memory is acceptable to go live?
  2. What is the alternate of navigation controller to support back button?

Thanks in advance.

like image 623
Sunil Avatar asked Jul 06 '10 11:07

Sunil


1 Answers

You might still have your UIViewControllers still retained if dealloc isn't being called.

Perhaps are you setting delegates or other classes in these UIViewControllers that retained and referenced back up the tree (circular references).

A way you can debug this is to overload retain and release in your UIViewController and set a break point and log the retainCount.

Here is a magic snippet I leave running around that helps me a ton when I can't figure out why I'm still retaining 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 a pretty Objective-C function name as a char array.

like image 174
Zac Bowling Avatar answered Sep 28 '22 14:09

Zac Bowling