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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:46:21+00:00 2026-05-26T02:46:21+00:00

SOLVED – it turns out that passing nil to removeObserver:forKeyPath: fails, but ONLY in

  • 0

SOLVED – it turns out that passing nil to removeObserver:forKeyPath: fails, but ONLY in manual memory management. It works fine in garbage collected mode. The Apple documentation does NOT say it requires a non-nil value so I’m assuming it’s a bug.

I have an object that adds itself as an observer of itself, via [self addObserver:self forKeyPath: etc. In my -dealloc method (note that I am using retain counts and NOT the garbage collector) I call [self removeObserver:self forKeyPath:nil]; which should work. However, I get the following error:

Cannot remove an observer <Snapshot 0x10047a6d0> for the key path "(null)" from <Snapshot 0x10047a6d0> because it is not registered as an observer.

Now, if I remove that line so it doesn’t remove itself, I get this message:

An instance 0x100193580 of class Snapshot was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
<NSKeyValueObservationInfo 0x1001be2f0> (
<NSKeyValueObservance 0x1001a0a00: Observer: 0x100193580, Key path: fileURL, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x1001a02f0>
)

So… the object is observing itself… and yet it isn’t? 😀 Notice in the second message, the observer has the same address as the instance being deallocated, so it is indeed the same object.

The line [self removeObserver:self forKeyPath:nil]; worked before when it was garbage-collected when called from -finalize but not now from -dealloc in manually managed code.

Any thoughts?

  • 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-05-26T02:46:21+00:00Added an answer on May 26, 2026 at 2:46 am

    Should the key path really be nil? from Apple documentation:

    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Protocols/NSKeyValueObserving_Protocol/Reference/Reference.html

    The key path, relative to the receiver, of the property to observe. This value must not be nil.

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

Sidebar

Related Questions

SOLVED: As it turns out, my problem was rooted in the fact that I
Solved I actually found out what is going on here. Turns out it was
- Solved - I Know they exist, but I haven't found a slider that
SOLVED http://jsfiddle.net/ArtofLife/u9d9d/ I have multiple TEXTAREA and BUTTON out side.. For inserting string in
Solved while writing this question, but posting in case it helps anyone: I'm setting
SOLVED - see Bish below I've got a list of checkboxes that all dump
Solved: Unfortunately I wasn't able to solve the problem but I started over and
Solved this ages ago, but this question recently got some attention so I'm adding
SOLVED: Thanks figured it out thanks to dominic hamon. It all boils down to
SOLVED! This works, I need to tell the compiler that T implements IEquatable 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.