---
title: "Which is the better way to remove self from NSNotificationCenter"  
description: "Which is the better way to remove self from NSNotificationCenter"  
author: "Tarun Kumar"  
published: 2015-07-14  
updated: 2015-07-14  
canonical: https://www.mindstick.com/forum/23336/which-is-the-better-way-to-remove-self-from-nsnotificationcenter  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Which is the better way to remove self from NSNotificationCenter

##### Which is the better way to remove self from NSNotificationCenter? Just remove self or remove self from the specific notification name?

I just want to know: Which is the better way to [remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden) [self](https://www.mindstick.com/articles/44535/smart-ways-to-secure-self-storage-facilities) from NSNotificationCenter in dealloc [method](https://www.mindstick.com/forum/166/webservice-method)? Or is [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) have met different [behaviors](https://www.mindstick.com/blog/304775/understanding-ad-targeting-using-demographics-interests-and-behaviours) between the two way?

PS. I just [catch](https://www.mindstick.com/forum/159341/how-to-use-try-and-catch-in-java-for-exception-handling-and-what-happens-when-an-exception-occurs) a weird thing that when I remove self from [notification](https://www.mindstick.com/blog/205/property-notification-in-c-sharp) center by the first way but the object which is dealloced still can recieve the notification, and this call a crash [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling) of course.

Just remove self by follow [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
 [[NSNotificationCenter  defaultCenter] removeObserver:self];
```

or remove self from the specific notification [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) like this:

```
 [[NSNotificationCenter  defaultCenter] removeObserver:self name:NotificationName object:someObj];
```

PS. I just catch a weird thing that when I remove self from notification center by the first way but the object which is dealloced still can recieve the notification, and this call a crash exception of course.

## Replies

### Reply by Uttam Misra

Re: Which is the better way to remove self from NSNotificationCenter? Just remove self or remove self from the specific notification name?

### Reply by Anonymous User

```
[[NSNotificationCenter defaultCenter] removeObserver:self];
```

that will remove all registrations where the observer is self

UIViewController could have its own registrations that it doesn't want removed in viewWillDisappear:. It's unlikely to register for any of the notifications in the public API using addObserver:selector:name:object:, because that would preclude you registering for them in your UIViewController subclass, but it could certainly register for non-public notifications now or in a future version.

A safe way to deregister is to send removeObserver:name:object: once for each registration:

```
- (void)deregisterForNotifications {NSNotificationCenter *center = [NSNotificationCenter defaultCenter];[center removeObserver:self name:someNotification object:nil];object:nil];}
```


---

Original Source: https://www.mindstick.com/forum/23336/which-is-the-better-way-to-remove-self-from-nsnotificationcenter

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
