-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Observation] ensure event triggers on deinitialization passes as if all properties that are being observed have changed (for weak storage) #79823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…all properties that are being observed have changed (for weak storage)
@swift-ci please smoke test macOS |
…r instead of testing weak value deinitialization time
@swift-ci please smoke test |
…lization and weak references
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test |
@swift-ci please smoke test |
phausler
added a commit
to phausler/swift
that referenced
this pull request
Jul 2, 2025
…all properties that are being observed have changed (for weak storage) (swiftlang#79823) * [Observation] ensure event triggers on deinitialziation passes as if all properties that are being observed have changed (for weak storage) * Add missing deinitialize method for synthetically triggering willSet * Correct the weak location for tests * Correct the test to actually test the deinitialization willSet trigger instead of testing weak value deinitialization time * Refine the tests for deinit triggers to more tightly trigger deinitialization and weak references * Correct missing trailing closure on deinit replacement * Ensure all potential ids are triggered at the deinitialization edge trigger
stephentyrone
pushed a commit
that referenced
this pull request
Jul 10, 2025
…e observations in memory (#82752) Explanation: This ensures a potential leak with SwiftUI and other systems using Observation do not leak observation closures when the potential Observable instances used are only weakly referenced inside the tracking closure. Scope: This is limited to the runtime behavior of Observable types and has no ABI or language level interactions. Issues: rdar://112167556 Original PRs: #79823 #82307 Risk: Low - This is very targeted to just Observation, however it is a behavioral change which does not make this a zero risk change. Testing: New unit tests were added to catch at least some of the potential cases this issue can occur with.
phausler
added a commit
to phausler/swift
that referenced
this pull request
Jul 30, 2025
…s as if all properties that are being observed have changed (for weak storage) (swiftlang#79823)" This reverts commit 9d1d917.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It was the case that
@Observable
types would participate in weak storage but not trigger change events when deallocating, that deinitialization pass would leave incorrect state in views or other systems that would track those values viawithObservationTracking
. This now lets that deinit post as if all tracked properties are inferring a willSet (but no didSet will occur).