Skip to content

[CmdPal] Fix memory leak in PerformanceWidgetsPage network band items - #48880

Merged
Michael Jolley (michaeljolley) merged 2 commits into
mainfrom
dev/mjolley/fix-cmdpal-perf-monitor-leak
Jun 25, 2026
Merged

Michael Jolley (michaeljolley) merged 2 commits into
mainfrom
dev/mjolley/fix-cmdpal-perf-monitor-leak

Conversation

@michaeljolley

Copy link
Copy Markdown
Contributor

Summary

Fixes a memory leak in the Performance Monitor dock extension where GetItems() created new ListItem instances for _networkUpItem and _networkDownItem on every call.

Problem

When the dock subscribes to ItemsChanged and calls GetItems() to refresh, the band page path allocates 2 new ListItem objects each time — the old ones are replaced in the fields but never collected (they remain referenced by the DockItemViewModel wrappers until the next refresh cycle). Under normal operation this leaks ~2 objects/second indefinitely.

Fix

Move _networkUpItem/_networkDownItem creation into the constructor (matching the pattern used by CPU, Memory, GPU, and Battery items). GetItems() now returns stable references. The Updated event handler already updates their .Title properties, which propagates to the UI via PropChanged → CommandItemViewModel.Model_PropChanged.

Validation

  • Build succeeds (Microsoft.CmdPal.Ext.PerformanceMonitor.csproj)
  • Network up/down band items still receive title updates via the existing Updated handler
  • No RaiseItemsChanged() needed — ListItem.Title setter fires PropChanged, which DockItemViewModel already observes

@github-actions github-actions Bot added the Product-Command Palette Refers to the Command Palette utility label Jun 25, 2026
@michaeljolley
Michael Jolley (michaeljolley) force-pushed the dev/mjolley/fix-cmdpal-perf-monitor-leak branch from d92a4d6 to f2cf615 Compare June 25, 2026 20:11
GetItems() was creating new ListItem instances for _networkUpItem and
_networkDownItem on every call. When used with the dock (which calls
GetItems() on each ItemsChanged event), this leaked 2 ListItem objects
per second indefinitely.

Move the network band item creation into the constructor so stable
instances are reused across calls, matching the pattern used by all
other metric items (CPU, Memory, GPU, Battery).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@michaeljolley Michael Jolley (michaeljolley) added 0.100.2 Hot Fix Items we will product an out-of-band release for labels Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a memory leak in the CmdPal Performance Monitor dock/band experience by ensuring the network up/down band items are stable objects rather than being re-created on every GetItems() refresh. This aligns the network band item lifecycle with the existing CPU/Memory/GPU/Battery patterns and avoids accumulating stale wrappers over time.

Changes:

  • Create _networkUpItem and _networkDownItem once in the constructor when isBandPage is true.
  • Remove the per-refresh allocation of those items from GetItems(), returning stable references instead.

@michaeljolley
Michael Jolley (michaeljolley) merged commit 28e0788 into main Jun 25, 2026
9 checks passed
@michaeljolley
Michael Jolley (michaeljolley) deleted the dev/mjolley/fix-cmdpal-perf-monitor-leak branch June 25, 2026 21:06
Boliang Zhang (LegendaryBlair) pushed a commit that referenced this pull request Jun 26, 2026
…#48880)

## Summary

Fixes a memory leak in the Performance Monitor dock extension where
`GetItems()` created **new** `ListItem` instances for `_networkUpItem`
and `_networkDownItem` on every call.

## Problem

When the dock subscribes to `ItemsChanged` and calls `GetItems()` to
refresh, the band page path allocates 2 new `ListItem` objects each time
— the old ones are replaced in the fields but never collected (they
remain referenced by the `DockItemViewModel` wrappers until the next
refresh cycle). Under normal operation this leaks ~2 objects/second
indefinitely.

## Fix

Move `_networkUpItem`/`_networkDownItem` creation into the constructor
(matching the pattern used by CPU, Memory, GPU, and Battery items).
`GetItems()` now returns stable references. The `Updated` event handler
already updates their `.Title` properties, which propagates to the UI
via `PropChanged` → `CommandItemViewModel.Model_PropChanged`.

## Validation

- Build succeeds (`Microsoft.CmdPal.Ext.PerformanceMonitor.csproj`)
- Network up/down band items still receive title updates via the
existing `Updated` handler
- No `RaiseItemsChanged()` needed — `ListItem.Title` setter fires
`PropChanged`, which `DockItemViewModel` already observes

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 28e0788)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

0.100.2 Hot Fix Items we will product an out-of-band release for Product-Command Palette Refers to the Command Palette utility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants