You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6)
Xcode Version 13.1 (13A1030d)
macOS Big Sur Version 11.6 (20G165)
Additional Detail from JIRA
Votes
0
Component/s
Foundation
Labels
Bug
Assignee
None
Priority
Medium
md5: 555024f1b9d5b4ae42896c0ae5f75845
Issue Description:
Hello! When I have an object create a Key-Value Observing observer for changes to that object's property's property (i.e. using a compound key path), no matter how I try to stop observing it, the deallocated observer ends up being notified of subsequent changes. In the best case this causes a crash. For example, running the following (from a file via swift bug.swift or in a Playground):
results in a crash at the indicated line. I see the "goodbye from" get printed, and I see the expected lack of printing from the change handler, but the program does not exit cleanly. The exact crash and stack trace can differ depending on what the address of the deallocated observer points to, but it includes _NSSetCharValueAndNotify and some private NSKeyValueObserving methods.
I first noticed this issue when using Combine's NSObject.KeyValueObservingPublisher, but narrowed it down to Swift's KVO observer. Using the old-style observeValue(forKeyPath:of:change:context:) works in the scenario I show above. Is this meant to be a supported configuration for Swift's KVO observer?
The text was updated successfully, but these errors were encountered:
Environment
Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6)
Xcode Version 13.1 (13A1030d)
macOS Big Sur Version 11.6 (20G165)
Additional Detail from JIRA
md5: 555024f1b9d5b4ae42896c0ae5f75845
Issue Description:
Hello! When I have an object create a Key-Value Observing observer for changes to that object's property's property (i.e. using a compound key path), no matter how I try to stop observing it, the deallocated observer ends up being notified of subsequent changes. In the best case this causes a crash. For example, running the following (from a file via
swift bug.swift
or in a Playground):results in a crash at the indicated line. I see the "goodbye from" get printed, and I see the expected lack of printing from the change handler, but the program does not exit cleanly. The exact crash and stack trace can differ depending on what the address of the deallocated observer points to, but it includes
_NSSetCharValueAndNotify
and some private NSKeyValueObserving methods.I first noticed this issue when using Combine's
NSObject.KeyValueObservingPublisher
, but narrowed it down to Swift's KVO observer. Using the old-styleobserveValue(forKeyPath:of:change:context:)
works in the scenario I show above. Is this meant to be a supported configuration for Swift's KVO observer?The text was updated successfully, but these errors were encountered: