Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jmagman
Copy link
Member

@jmagman jmagman commented May 13, 2024

Removing NSNotificationCenter observers in dealloc hasn't been necessary since iOS 8 or macOS 10.10.

If your app targets iOS 9.0 and later or macOS 10.11 and later, and you used addObserver:selector:name:object:, you do not need to unregister the observer. If you forget or are unable to remove the observer, the system cleans up the next time it would have posted to it.

https://developer.apple.com/documentation/foundation/nsnotificationcenter/1413994-removeobserver

Remove it.

weakDelegate = delegate;
}
XCTAssertNil(weakPlugin);
XCTAssertNil(weakDelegate);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails on main due to the retain cycle:

__block NSObject* blockSelf = self;
dispatch_block_t unsubscribe = ^{
[[NSNotificationCenter defaultCenter] removeObserver:blockSelf name:name object:nil];
};
[_notificationUnsubscribers addObject:[unsubscribe copy]];

@jmagman jmagman force-pushed the observer-remove branch from 615f051 to 33246e1 Compare May 13, 2024 19:58
Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jmagman jmagman marked this pull request as ready for review May 13, 2024 20:48
@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label May 13, 2024
@auto-submit auto-submit bot merged commit 7dcbd93 into flutter:main May 13, 2024
@jmagman jmagman deleted the observer-remove branch May 13, 2024 20:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

affects: desktop autosubmit Merge PR when tree becomes green via auto submit App platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants