Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7852131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:21:00+00:00 2026-06-02T19:21:00+00:00

Looking at various Apple examples (for example Add Music ) in which I see

  • 0

Looking at various Apple examples (for example Add Music) in which I see they add observers to the default NSNotificationCenter in viewDidLoad, then remove them in dealloc. This seems dangerous as viewDidLoad can be called multiple times without dealloc being called. This would then add the same observer multiple times, causing the handler to be called multiple times.

A solution to this would be to also remove observers in viewDidUnload, but this would then mean the same observer could be removed for a second time in dealloc which seems like a potential problem.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:21:01+00:00Added an answer on June 2, 2026 at 7:21 pm

    There are a lot of discussions about removing notifications in the right way. For example:

    • removeobserver-with-nsnotification-what-am-i-doing-wrong
    • removing-a-nsnotificationcenter-observer-in-ios-5-arc

    I suggest you to remove observers in viewWillDisappear (or viewDidDisappear) and viewDidUnload lifecycle methods. (Note: viewDidUnload was deprecated and shouldn’t be implemented in iOS6+; see iOS 6 – viewDidUnload migrate to didReceiveMemoryWarning?)

    An important note:

    viewDidUnload is not guaranteed to be called – it’s not a standard lifecycle method.

    From Apple doc:

    viewDidUnload
    When a low-memory condition occurs and the current view controller’s
    views are not needed, the system may opt to remove those views from
    memory. This method is called after the view controller’s view has
    been released and is your chance to perform any final cleanup.

    Instead, dealloc is called whenever the number of references for that receiver is zero.

    Hope it helps.

    Edit

    For the sake of completeness you can see this link on how to avoid-nsnotification-removeobserver. The link provide some useful guidelines to remove observer (see also the comments). The author does it in viewDidAppear/viewDidDisappear methods since viewWillAppear and viewWillDisappear are not always called correctly in many applications.
    It’s your choice.

    If you want to be sure to remove observers in the right way unregister it in dealloc method or when the view is fully unloaded as you wrote in the second comment.
    But be sure that dealloc will be call in the future. In other words, as I already mentioned, if the controller continues to stay alive since some other object has a referenced to it, the method will never get called. In this case the controller continues to receive notifications.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for the smartest/various way of handling categories in App Engine. I see
We are looking for various options which will help us to record audio and
Looking at various examples, below is what seems to be the correct way of
When looking at various web pages, I sometimes see statements like the following in
I've been looking through various websites and came across multiple ways to make buttons.
I am looking into various OS designs in the hopes of writing a simple
Hey, I'm currently looking for various methods of implementing collision response in 2D video
I was looking at the various windows styles flags, and I noticed that a
I'm looking into the various methods of rate limiting the Django admin login to
I've been looking at Boost and various other C++ libraries. The vast majority of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.