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 8623023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:11:14+00:00 2026-06-12T07:11:14+00:00

When I use -addObserverForName: object: queue: usingBlock: for NSNotificationCenter in the -viewDidLoad: method of

  • 0

When I use -addObserverForName: object: queue: usingBlock: for NSNotificationCenter in the -viewDidLoad: method of my view controller, the -dealloc method ends up not being called.

(When I remove -addObserverForName: object: queue: usingBlock:, -dealloc is called again.)

Using -addObserver: selector: name: object: doesn’t seem to have this problem. What am I doing wrong? (My project is using ARC.)

Below is an example of my implementation, in case I’m doing something wrong here:

[[NSNotificationCenter defaultCenter] addObserverForName:@"Update result"
                                                  object:nil
                                                   queue:nil
                                              usingBlock:^(NSNotification *note) {
                                                  updateResult = YES;
                                              }];

Thanks in advance for any help.

I’ve tried adding the following (to no avail):

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    if ([self isMovingFromParentViewController]) {
        [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
}
  • 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-12T07:11:16+00:00Added an answer on June 12, 2026 at 7:11 am

    updateResult is an instance variable which prevents the object from being deallocated as it is retained by that block.

    In other words, you got a retain cycle. The object retains the block and the block retains the object.

    You will need to create a weak or unsafe_unretained reference to that instance and its variable for loosing that relationship.

    Add the following prior to your notification block:

    __unsafe_unretained YouObjectClass *weakSelf = self;
    

    or (in case you are on iOS5 and above)

    __weak YouObjectClass *weakSelf = self;
    

    Then, within that block, reference the object via that new weak reference:

    [[NSNotificationCenter defaultCenter] addObserverForName:@"Update result"
                                                      object:nil
                                                       queue:nil
                                                  usingBlock:^(NSNotification *note) {
                                                      weakSelf.updateResult = YES;
                                                  }];
    

    Please note that retain-cycles are not a bad thing per se. Sometimes you actually want them to happen. But those are instances where you are certain that the cycle will be broken after a specific time (e.g. Animation Blocks). The cycle is broken once the block has executed and is removed from the stack.

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

Sidebar

Related Questions

use ThreadPool.QueueUserWorkItem (WaitCallback, Object) to start a thread with my target method and data.
use javascript or other method ? have any recommendation?
Use case: I find a piece of code that I do not understand at
Use cardova 2.0.0. After Compilations app show error: Could not find class 'android.webkit.WebResourceResponse', referenced
Use the grow() method to modify a rectangle to be twice as large. I'm
Use Case: Admin should be able to create user, and it should not attempt
USE [Fk_Test2] GO /****** Object: Table [dbo].[Owners] Script Date: 08/20/2010 16:52:44 ******/ SET ANSI_NULLS
Use of rails 3 recaptcha. In view _form.html.erb insert <%= recaptcha_tags %> But when
Use case: I'm using data templates to match a View to a ViewModel. Data
use messagepack on android, the can serialize/deserialize a class, but not absolutely right .

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.