Testing if an object has been freed

I have a situation where sometimes my method -tableView: numberOfRowsInSection:requests an account of freed NSArray. I would like to have the opportunity to check if this array is freed so that it is safe and does not cause zombies.

At the moment, my code is as follows:

-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
    if (! self.offers){
        return 0;
    }
    return [self.offers count];
}

I just went through this debugger and watched how it passed the test ! self.offers, and then brutally collapsed on [self.offers count]. I have NSZombies enabled, and on this line I get the NSLog message:

-[__NSArrayM count]: message sent to deallocated instance 0x283dc0

Thus, no matter what, in fact, it is not zero, but also does not indicate anything real. How can I check this?

: , . , - , . . : , .

+3
6

"" - , , - . - .

, , - , ( ) offers - , , .

(Build- > Build and Analyze), - .

+15

, , , .

+1

-(void)dealloc { ... }

, , .

ARC NON-ARC

+1

(, ) - , , UITableViewController, , - .

0

, quixoto .

, , - , ? Tableview , ( offers), , - , .

, - , "" , , , , /.

0

, , , - . - .

. . ( !): BOOL, alloc. , AVAudioPlayer isPlaying. , , . - .. [newPlayer isPlaying] , ! , BOOL . ( .)

// In implementation
static AVAudioPlayer *newPlayer;
static BOOL hasMusicFinishedPlaying;

// When Playing the music, set flag
    newPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath: soundPath] error:nil];    
    hasMusicFinishedPlaying = NO;

// Callback method to release new player in playKeySound
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)newPlayer successfully:(BOOL)flag {

    [newPlayer release];
    hasMusicFinishedPlaying = YES;
}

// On going back to another page. We don't want to keep ViewController in stack.

    if (!hasMusicFinishedPlaying){
        return;
    }

    [self.navigationController popViewControllerAnimated:YES];
0

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


All Articles