|
| 1 | +# ScreenToGif — `SystemEvents.DisplaySettingsChanged` subscribed, never detached |
| 2 | + |
| 3 | +**Found by mining** (P-004 milestone 1, see `docs/notes/real-world-mining.md`), |
| 4 | +surfaced once the WPF reference pack was loaded (`OWN_EXTRA_REF_DIRS`). Target: |
| 5 | +`NickeManarin/ScreenToGif` @ `27a49c3`, **two** independent occurrences: |
| 6 | + |
| 7 | +- `ScreenToGif/Windows/Other/GraphicsConfigurationDialog.xaml.cs:35` |
| 8 | +- `ScreenToGif/Windows/Other/Troubleshoot.xaml.cs:27` |
| 9 | + |
| 10 | +**Pattern.** A `Window` subscribes to `Microsoft.Win32.SystemEvents.DisplaySettingsChanged` |
| 11 | +with a method-group handler and never unsubscribes. `SystemEvents` is a **static, |
| 12 | +process-lifetime** class; its events hold a strong reference to every subscriber |
| 13 | +for the life of the process. The window closes but cannot be collected — the |
| 14 | +canonical SystemEvents leak that the .NET docs explicitly warn about. |
| 15 | + |
| 16 | +**What the checker says (real extractor output, WPF profile on):** |
| 17 | + |
| 18 | +```text |
| 19 | +GraphicsConfigurationDialog.xaml.cs:35: error: [OWN001] event |
| 20 | + 'SystemEvents.DisplaySettingsChanged' is subscribed (handler |
| 21 | + 'SystemEvents_DisplaySettingsChanged') but never unsubscribed — the source keeps |
| 22 | + 'GraphicsConfigurationDialog' alive (leak) [resource: subscription token] |
| 23 | +``` |
| 24 | + |
| 25 | +**Why error, not warning (the tiering).** Contrast the `VideoSource` finding next |
| 26 | +door (`screentogif-loaded-subscription/`), which the extractor rates a *warning* |
| 27 | +because its source is an *injected* field of unknown lifetime. Here the source is a |
| 28 | +**static** event, so it *provably* outlives the window — the P-004 severity tiering |
| 29 | +classifies it `static` and the leak is a hard **error**, not a "possible leak". The |
| 30 | +extractor draws that line from the source's lifetime, exactly as designed. |
| 31 | + |
| 32 | +**This `case.own`** models the subscription as a generic acquire/release, so it |
| 33 | +produces the core's domain-neutral **OWN001** (which already defaults to error — |
| 34 | +matching the static-source tier; the warning/error split for injected sources lives |
| 35 | +in the C# extractor, above the core). As elsewhere in the corpus, `case.own` is a |
| 36 | +hand reduction; `before.cs` / `after.cs` capture the leak and its fix. |
0 commit comments