Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

NSObject+BlockObservation.h documentation warning #76

Closed
pocketpixels opened this issue Apr 13, 2012 · 2 comments
Closed

NSObject+BlockObservation.h documentation warning #76

pocketpixels opened this issue Apr 13, 2012 · 2 comments

Comments

@pocketpixels
Copy link

The NSObject+BlockObservation.h header contains the following warning near the top:

@warning Important: Due to a design flaw in some recent versions of the
Objective-C runtime, you must call removeObserverWithBlockToken: in the
dealloc method of any object making use of block-based KVO.

This refers to a method that doesn't exist in the current implementation (-removeObserverWithBlockToken:).
Is this warning still relevant? Does it mean that -removeAllBlockObservers can not be relied upon? If so, maybe the warning should be added to that method? Or maybe the -removeAllBlockObservers method should be deprecated/removed if it does not work on some OS versions?

@zwaldowski
Copy link
Collaborator

Ah, no, whoops, I'll clarify that behavior in the future. All removal methods, -removeObserverForKeyPath:identifier:, -removeAllBlockObservers, and the future -removeObserversWithIdentifier:, work perfectly on every OS version.

Since iOS 3.1, we've had the runtime feature of associated objects, which BlocksKit uses to implement many features from within categories. The runtime is supposed to remove/release all associated objects on deallocation, obviating the need to call a block KVO removal method unless you want to. However, due to a bug in the runtimes of iOS 4.x and OS X 10.6, this occasionally doesn't happen when the associated object is hooked in to KVO. In other words, in a BlocksKit-based application supporting OS X 10.6 or iOS 4.x, we recommend manually removing block observers to prevent memory leaks and/or crashes.

@pocketpixels
Copy link
Author

Great, thanks for clarifying that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants