Skip to content

Conversation

phausler
Copy link
Contributor

@phausler phausler commented Mar 6, 2025

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 via withObservationTracking. This now lets that deinit post as if all tracked properties are inferring a willSet (but no didSet will occur).

…all properties that are being observed have changed (for weak storage)
@phausler phausler requested a review from a team as a code owner March 6, 2025 20:33
@phausler
Copy link
Contributor Author

@swift-ci please smoke test macOS

…r instead of testing weak value deinitialization time
@phausler
Copy link
Contributor Author

phausler commented Apr 3, 2025

@swift-ci please smoke test

@phausler
Copy link
Contributor Author

phausler commented Apr 3, 2025

@swift-ci please smoke test

@phausler
Copy link
Contributor Author

phausler commented Apr 3, 2025

@swift-ci please smoke test

@phausler
Copy link
Contributor Author

phausler commented Apr 4, 2025

@swift-ci please smoke test

@phausler
Copy link
Contributor Author

phausler commented Apr 4, 2025

@swift-ci please smoke test

@phausler phausler merged commit 9d1d917 into swiftlang:main Apr 7, 2025
3 checks passed
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant