Skip to content

[VS] Status bar indicator leaks a view model on every status update, each one subscribed to VSColorTheme.ThemeChanged: a theme change then freezes Visual Studio #256

Backlog

Description

@xperiandri

Current behavior

Visual Studio stops responding (UI frozen, one core at 100%) after the Uno Platform extension has been running for a while, as soon as Visual Studio raises a theme change.

Managed stacks of the hung devenv.exe (ClrMD) show the UI thread inside VSColorTheme.ThemeChangedCallback → ThemeChangedEventHandler.Invoke, and the same frame in two snapshots taken several seconds apart. The VSColorTheme.ThemeChanged event (ThemeChangedStorage) has 27,439 subscribers, and 27,418 of them are Uno.IDE.UnoDevelopmentEnvironmentIndicatorViewModel.OnThemeChanged. The heap holds 27,418 UnoDevelopmentEnvironmentIndicatorViewModel instances and a single UnoDevelopmentEnvironmentIndicatorView, after about 38 hours of uptime (roughly 12 leaked view models per minute).

The cause, as seen in Studio.Extensions.dll 7.0.4 (decompiled), is UnoDevelopmentEnvironmentIndicator.EnsureInitAsync:

if (Interlocked.CompareExchange(ref _model, new UnoDevelopmentEnvironmentIndicatorViewModel(commands, telemetry), null) == null)
{
    // first call only: put the view into the status bar
}
return _model;

The new UnoDevelopmentEnvironmentIndicatorViewModel(...) argument is evaluated on every call, that is on every status change that reaches UpdateAsync, even when _model is already set. The constructor does

VSColorTheme.ThemeChanged += OnThemeChanged;
ThemeBrushes.UpdateRowButtonResources();

so each discarded instance stays rooted forever by the static event, and each construction also writes six brushes into Application.Current.Resources.

When the theme changes, every leaked instance runs OnThemeChanged → RefreshIcons() on the UI thread: it rebuilds its entries, queues four PropertyChanged notifications through SwitchToMainThreadAsync, and calls ThemeBrushes.UpdateRowButtonResources() again. With 27,418 instances this means about 165,000 writes to application-level resources, each of which invalidates resource lookups across the whole WPF tree. That is most likely what keeps the UI thread busy; Visual Studio did not recover while I watched it.

Expected behavior

One UnoDevelopmentEnvironmentIndicatorViewModel per indicator, one ThemeChanged subscription, and a theme change that costs one refresh.

Which tool(s) are affected?

Uno Platform extension for Visual Studio: the development environment status indicator in the status bar (UDEI). None of the listed tools matches exactly.

How to reproduce it (as minimally and precisely as possible)

  1. Open a solution with Uno Platform projects in Visual Studio with the Uno Platform extension 7.0.4.4, so that the dev server starts and the status indicator receives status messages.
  2. Keep Visual Studio open for some hours of normal work: every status change of the indicator leaks one view model.
  3. Change the Visual Studio color theme (or let it follow a Windows theme change).
  4. Visual Studio freezes for as long as the leaked instances take to refresh.

A faster check without waiting for the freeze: after some status changes, count the UnoDevelopmentEnvironmentIndicatorViewModel instances in a memory dump, or the subscribers of VSColorTheme.ThemeChanged.

Workaround

Restart Visual Studio regularly, and avoid theme changes in a long-running instance.

Renderer

No response

Affected platforms

No response

Uno.Sdk version

6.7.45

IDE used

Visual Studio 2026

IDE version

Visual Studio Enterprise 2026 Insiders 18.13.12412.241

Uno Platform Extension version

7.0.4.4 (Studio.Extensions.dll 7.0.4+899d02ca9d4199db7255008beab2ea512c5de8f8)

Relevant plugins

CodeRush, cv4vs Agents. Neither is involved: the subscribers above belong to the Uno extension (8 others come from other extensions and Visual Studio itself).

Anything else we need to know?

A possible fix:

private async ValueTask<UnoDevelopmentEnvironmentIndicatorViewModel> EnsureInitAsync(CancellationToken ct)
{
    if (Volatile.Read(ref _model) is { } existing)
    {
        return existing;
    }

    var created = new UnoDevelopmentEnvironmentIndicatorViewModel(commands, telemetry);
    if (Interlocked.CompareExchange(ref _model, created, null) is { } winner)
    {
        created.Dispose(); // unsubscribes from VSColorTheme.ThemeChanged
        return winner;
    }

    await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(ct);
    await statusBarService.GetElement("udei").SetContentAsync(new UnoDevelopmentEnvironmentIndicatorView { DataContext = created }, ct);
    return created;
}

plus UnoDevelopmentEnvironmentIndicatorViewModel : IDisposable with VSColorTheme.ThemeChanged -= OnThemeChanged. It would also help to move ThemeBrushes.UpdateRowButtonResources() out of the view model into a single process-wide ThemeChanged handler, since those resources are global anyway.

The implementation lives in a repository I cannot access, so I could not open a pull request; the interface and the callers are in unoplatform/uno (src/Uno.UI.RemoteControl.VS/VSIXChannel/IUnoDevelopmentEnvironmentIndicator.cs, EntryPoint.cs).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions