Commit fdd5052
Fix retain cycles in AnnouncementsDataStoreTests and GutenbergVideoUploadProcessor (#25548)
* Fix retain cycle in AnnouncementsDataStoreTests
Each of the four tests stores `subscription = store.onChange { … store.x … }`
in an instance property. The closure captures the local `store` strongly,
which is then retained by `CachedAnnouncementsStore.changeDispatcher`'s
observers dictionary, forming the cycle:
store → changeDispatcher → observers[token] → closure → store
Without a `tearDown`, the `Receipt` only deinits when XCTest tears down the
test instance, which it defers when more tests are queued in the class —
so the cycle is observable by the end-of-test leak snapshot.
Adding `tearDown` to nil out `subscription` triggers the `Receipt.deinit`
unsubscribe path immediately and breaks the cycle.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* Fix retain cycle in GutenbergVideoUploadProcessor
The three `lazy var` properties (`videoHtmlProcessor`, `videoBlockProcessor`,
`mediaTextVideoBlockProcessor`) each construct a child processor whose
`replacer:` closure references `self` without a capture list. The child
processor is owned strongly by `self`, and the closure retained inside it
captures `self` strongly — producing three independent 2-node cycles:
GutenbergVideoUploadProcessor
→ videoHtmlProcessor (HTMLProcessor)
→ replacer.context → captures self
→ GutenbergVideoUploadProcessor (cycle)
Switching each closure to `[weak self]` (with a `guard let self` early-out)
breaks the back-edge. By ownership, the closure is only invoked while
`self` is still alive, so the guard never trips in practice.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 92fd2b4 commit fdd5052
2 files changed
Lines changed: 13 additions & 5 deletions
File tree
- Tests/KeystoneTests/Tests/Features/Misc/WhatsNew
- WordPress/Classes/ViewRelated/Gutenberg/Processors
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
| |||
Lines changed: 8 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
34 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
56 | | - | |
57 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
58 | 61 | | |
59 | 62 | | |
60 | 63 | | |
| |||
0 commit comments