IPhone EXC_BAD_ACCESS when calling [super dealloc] on user UIViewController

I am at a loss! This is one of those nasty mistakes that happen only under certain conditions, but I cannot directly relate the conditions and results.

My application has paged UIScrollView, where each pageview comes from MyViewController, a subclass of UITableViewController. To minimize memory usage, I unload controllers that are currently not visible. Here is my "cleanup" method:

- (void) cleanViewControllers:(BOOL)all {

    if (all) { 
    // called if some major changes occurred and ALL controllers need to be cleared

        for (NSInteger i = 0; i < [viewControllers count]; i++)
            [viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];
    }
    else if ([viewControllers count] > 2) {
    // called if only the nearest, no longer visible controller need to be cleared
        NSInteger i = pageControl.currentPage - 2;
        if (i > -1) [viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];
        i = pageControl.currentPage + 2;
        if (i < [viewControllers count]) [viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];
    }
}

This is the line that causes the application to crash:

viewControllers replaceObjectAtIndex:i withObject:[NSNull null]];

viewControllers is an NSMutableArray containing objects of type MyViewController. MyViewController has no custom properties, and its dealloc method contains nothing but a call to [super dealloc].

: alt text http://a.imageshack.us/img831/3610/screenshot20100806at126.png

, , , . , , ScrollView, ( X) , , X, . !

, 4.0 iPad, iPod 1- , 3.1.3.

+3
4

- , . NSZombieEnabled YES . :

  • → Active Executable
  • ""
  • ", "
    • : NSZombieEnabled
    • : YES

. - , . , .

.

+6

-, - ViewController, , :

UIBarButtonItem* timeLabel = [[UIBarButtonItem alloc] initWithTitle:@"time" style:UIBarButtonItemStylePlain target:nil action:nil];

NSArray *items = [NSArray arrayWithObjects: timeLabel, nil];

self.toolbarItems = items;

:

[timeLabel release];

EXC_BAD_ACCESS [super dealloc], , AND .

+1

, , .

? - [viewController isViewLoaded] && viewController.view.superview. , , .

( isViewLoaded, UIViewController.view , .)

0

, , removeObjectAtIndex: removeAllObjects:, , , .

-1
source

Source: https://habr.com/ru/post/1758448/


All Articles