0
votes

I've searched a lot but unlucky didn't find a similar one that could solve my problem.

For example, I'm not using delegate so strong delegate pointer is not the problem.

There is a UItabbarcontroller as a root view controller. After loading that tab bar controller, it will present a view controller (modally) on top. Once that view controller finished its job, dismiss the view controller and get back to TabBarController. The reason for this is in that view controller it has a background image which consumed about 10mb memory.

I present the view controller in -viewDidAppear:

- (void)viewWillAppear:(BOOL)animated
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    if ([userDefaults valueForKey:@"token"]==NULL) {
        UIStoryboard *storyboard = [self storyboard];
        UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:@"SignInNavigationController"];

        [self presentViewController:navController animated:NO completion:nil];
    }
}

That navigation controller is root controller of that view controller. (I hope this is not the problem)

And this is how I dismiss the view controller:

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

There is no other connection between them.

EDIT: Someone asked about what is the question, so my question is since that view controller is dismissed, the memory of that should be collected back right? Or if not, is there anyway to collect it back?

(ARC of course)

1
and what is the problem? the SignInNavigationController is never deallocated? Or is maybe just the image never deallocated? You can add the -(void)dealloc method to the SignInNavigationController and put a breakpoint inside in order to find out, whether or not this is really your problem!Nils Ziehn

1 Answers

3
votes

It depends on how you are loading the image. If you are using imageNamed: on UIImage the image you load will actually get cached. This is true also if the image is loaded via XIB or storyboard. Assuming there isn't some other retain cycle issue, the cache will get purged when a low memory notification is posted.

If you're wanting to be more proactive than that, then do not load the image via XIB, storyboard, or the imageNamed: API on UIImage. Instead, use the imageWithContentsOfFile: API.