user435739
user435739

Reputation:

Sending Notification from a timer handler cocoa

I have a timer which was started by main thread. From timer handler I am sending notification In 1 out of 5 cases, I get EXC_BAD_ACCESS when the post notification code is executed.

//Registering Notification
    [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(TestNotification:)
                   name:@"TestNotification" object:nil];

//Starting timer
        timer = [NSTimer scheduledTimerWithTimeInterval:2
                                                 target:self 
                                               selector:@selector(timerhandler:) 
                                               userInfo:nil 
                                                repeats:YES];    


    //Posting notification from timer handler    
        [[NSNotificationCenter defaultCenter]   
             postNotificationName:@"TestNotification" object:nil];

Can someone help.

Thanks

Upvotes: 0

Views: 258

Answers (1)

Vincent Bernier
Vincent Bernier

Reputation: 8664

At first it looks like an object that have registered to receive notification didn't unregister before getting deallocated.
Resulting in the Notification center sending a message to a deallocated object.

But without more code it's hard to say more.

Upvotes: 1

Related Questions