1

In an ARC project, I addObserver for a notification in viewDidLoad: and removeObserver: in dealloc. But after I pop the viewController, dealloc is not executed.

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(refreshData)
                                                 name:MyNotification
                                               object:nil];
}

- (void)dealloc
{
    NSLog(@"==================");//There is nothing print out.
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MyNotification
                                                  object:nil];
}

Thanks.

1 Answer 1

5

this may perhaps you have enabled nszobie objects, disable them. i don't know why but if nszombie enabled in arc, dealloc is not invoked.

go to product>edit schems> unchek the enable zombie

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.