[CmdPal] Fix memory leak in PerformanceWidgetsPage network band items#48880
Merged
Conversation
d92a4d6 to
f2cf615
Compare
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>
niels9001
approved these changes
Jun 25, 2026
Contributor
There was a problem hiding this comment.
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
_networkUpItemand_networkDownItemonce in the constructor whenisBandPageis true. - Remove the per-refresh allocation of those items from
GetItems(), returning stable references instead.
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a memory leak in the Performance Monitor dock extension where
GetItems()created newListIteminstances for_networkUpItemand_networkDownItemon every call.Problem
When the dock subscribes to
ItemsChangedand callsGetItems()to refresh, the band page path allocates 2 newListItemobjects each time — the old ones are replaced in the fields but never collected (they remain referenced by theDockItemViewModelwrappers until the next refresh cycle). Under normal operation this leaks ~2 objects/second indefinitely.Fix
Move
_networkUpItem/_networkDownItemcreation into the constructor (matching the pattern used by CPU, Memory, GPU, and Battery items).GetItems()now returns stable references. TheUpdatedevent handler already updates their.Titleproperties, which propagates to the UI viaPropChanged→CommandItemViewModel.Model_PropChanged.Validation
Microsoft.CmdPal.Ext.PerformanceMonitor.csproj)UpdatedhandlerRaiseItemsChanged()needed —ListItem.Titlesetter firesPropChanged, whichDockItemViewModelalready observes