Files
PowerToys/src/modules
copilot-swe-agent[bot] 5958c16285 fix: prevent memory leak in CmdPal extension activation via global hotkey
Fixes a race condition where _initializeItemsTask subscribes to COM events
on IListItem/IPage objects after SafeCleanup has already run, leaving those
subscriptions permanently alive (held by the cross-process COM event
registration in the extension process).

Changes:
- ExtensionObjectViewModel: add IsCleanedUp volatile property, set before
  UnsafeCleanup() so background threads see it immediately
- CommandItemViewModel.InitializeProperties: guard against IsCleanedUp
  at entry and after subscribing (double-check to close the race window)
- PageViewModel.InitializeProperties: same guard pattern for page PropChanged
- ListViewModel.UnsafeCleanup: unsubscribe _lastSelectedItem.PropertyChanged
  to sever the delegate chain that keeps ListViewModel alive
- ShellViewModel.LoadPageViewModelAsync: call SafeCleanup() (not just Dispose)
  when navigation is cancelled; use CancellationToken.None for the UI-thread
  task so the cleanup lambda always runs even if the token is already cancelled

Agent-Logs-Url: https://github.com/microsoft/PowerToys/sessions/0bf9ec35-b19d-4ea4-971d-803a1d4f305e

Co-authored-by: MuyuanMS <116717757+MuyuanMS@users.noreply.github.com>
2026-04-29 11:13:29 +00:00
..