Pregunta

In my app if I have a view that has been deallocated (via modal dismiss or navigation stack pop) and I get a memory warning after that, my app crashes.

I've tested by putting a modal create/dismiss very early on in my app that looks like this:

WWebViewController *webViewController = [[WWebViewController alloc] initWithPath:@"http://www.google.com"];
        [webViewController setIsModal:YES];
        WMainNavController *navController = [[WMainNavController alloc] initWithRootViewController:webViewController];
        [self presentViewController:navController animated:YES completion:nil];

The web view is pretty simple:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNavigationDefaultsWithTitle:@"Loading..." withBackButton:YES withSearchButton:YES deepLinked:false];
    webView = [[UIWebView alloc] initWithFrame:[self.view bounds]];
    webView.delegate = self;
    [self.view addSubview:webView];
    [webView scalesPageToFit];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.path]]];
    [self showNoConnectionImageIfNecessary:NO];
    // Do any additional setup after loading the view.
}

...

- (void)dealloc {
    [webView loadHTMLString:@"" baseURL:nil];
    [webView stopLoading];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    [webView setDelegate:nil];
    webView = nil;
}

However, simply presenting and then dismissing this view followed by simulating a memory warning gives this:

*** -[WMainNavController retain]: message sent to deallocated instance 0xba953c0

I've tried this by calling WWebViewController directly without WMainNavController, tried by using a regular navigation controller, tried simply pushing something to a nav stack. It always crashes if I have popped or dismissed a view anywhere in the app.

Am I doing something fundamentally wrong? If I progress through the app without dismissing/popping it handles memory warnings fine, and there is only one screen before this which presents this screen as a modal and is the root view of the program.

I'll provide any extra information needed, has anybody seen something like this?

Edit -- This is an ARC implementation.

Edit -- Here is a screenshot of my instruments with zombies on:

enter image description here

It looks to me as everything is normal. It deallocates properly on dismissal, but for some reason the memory warning call is trying to access that view controller. I'm at a total loss.

¿Fue útil?

Solución

For anyone who comes across a similar issue, I can't really explain how to fix it, but I can tell you what I did to make my issue magically disappear.

I essentially began removing any categories/controllers/whatever that affect many or all other major components of my app from compile sources in the build phases of my target. I then commented out code accordingly so my app would build to where I needed it to go to test. Eventually I isolated a UIViewController category that was 'causing the issue' and removed all of the methods from it as well as an NSString extern variable.

This fixed the problem, but when I was trying to figure out what method was causing it...turns out none of them were. When I uncommented everything and was back to where I started with the category it continued to work, no more crashes.

I'm happy it works now, but damned mystified that I'll never really know why it broke in the first place.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top