Repository navigation
Description
Current behavior 🐛
Uno.UI.RemoteControl.Host.exe (DevServer 6.6.184) grows by hundreds of MB per edit/build cycle of the solution it watches, never releases it, and reaches ~16 GB over a working day. On a 31.6 GB machine it becomes the top consumer in every Windows Resource-Exhaustion event (System log, Event ID 2004: 14 events on 2026-08-20 alone, plus every such event across six other days in August), and Windows starts terminating unrelated applications.
Controlled measurement (2026-08-20, details below) shows the growth is per-recompile, not per-unit-time, and that three things compound:
1. Every recompile permanently accumulates assemblies in the default AssemblyLoadContext.
dotnet-counters on a DevServer whose watched solution was being edited (agent-driven session, MCP path, no IDE channel, and notably no app connected):
| Time | dotnet.assembly.count |
Watched solution activity |
|---|---|---|
| 15:38:45 | 988 | quiet |
| 15:49:10 | 988 | quiet (flat for 10.5 min) |
| 15:51:15 | 1,050 | edits + rebuilds |
| 15:57:35 | 1,184 | edits + rebuilds |
+196 assemblies in 8 minutes, monotonic, never falls. AssemblyHelper.cs loads add-ins via Assembly.LoadFrom into AssemblyLoadContext.Default (its own doc comment: "Every add-in lives in the same AssemblyLoadContext as the host"), so nothing loaded this way can ever be unloaded.
2. Roslyn compilation state is retained. A dotnet-gcdump of the grown process (which forces a blocking gen2 GC) shows the surviving heap dominated by Microsoft.CodeAnalysis: syntax/trivia TextKeyedCache arrays, GreenNode[], PENamedTypeSymbol, MetadataReference, and incremental generator Entry<Object, IStateTable> tables. The heap graph exceeded gcdump's 10,000,000-node cap.
3. Server GC hides the problem until the OS kills something. The shipped Uno.UI.RemoteControl.Host.runtimeconfig.json sets "System.GC.Server": true. On a 16-core machine that produced exactly 1 gen2 collection in 19 minutes while gen2 grew monotonically from 2,373 to 3,172 MB, with 2.37 TB of reserved address space. The forced GC from gcdump reclaimed ~1 GB instantly (5,948 to 4,965 MB), so a large share of the commit is collectable garbage the GC feels no pressure to collect. The Windows commit limit is reached long before the .NET GC reacts. Note DOTNET_gcServer=0 cannot override this: runtimeconfig.json wins.
Growth-to-edit correlation on the affected DevServer (private bytes, Get-Process sampling at 15 s):
| Watched-solution activity (file timestamps) | DevServer response |
|---|---|
| edits 15:29-15:31 | 2,728 -> 4,739 MB |
| no edits 15:43-15:49 | +1.0 MB over 6.4 min (0.16 MB/min) |
| edits 15:52-15:55 (3 files) | +263 MB in 48 s |
| edits 16:14 + full build 16:16 | +470 MB in 5 min |
Control experiment: a freshly started DevServer for a stock dotnet new unoapp solution, with no app ever connected (so no ConfigureServer, no hot-reload workspace), stays inert at ~37 MB / 155 assemblies and does not react to any builds, including full builds of its own solution. The accumulation engine is the hot-reload workspace (MSBuildWorkspace + HotReloadManager + FileSystemObserver); once initialized it recompiles on every file change even when no app and no IDE are connected, so the memory is spent producing updates that nothing consumes.
Scale summary:
| Process | State | Private bytes |
|---|---|---|
| fresh DevServer, idle 10 min, no client | inert | 46 MB |
| DevServer after ~85 min of an active session's edit cadence, no app connected | grown | ~5,900 MB (~4,965 MB immediately after a forced gen2 GC) |
Expected behavior 🎯
A hot-reload broker's memory should stay proportional to the live state of one solution's workspace. Editing and rebuilding an app all day should not grow the DevServer to 16 GB, and a DevServer with no connected client should not be compiling at all.
Proposed directions, in impact order:
- Load add-ins into collectible
AssemblyLoadContexts. The warning text inAssemblyHelper.csalready recommends exactly this (its option 2) to add-in maintainers, and the host already has the pattern in-tree for analyzers (CollectibleAnalyzerAssemblyLoader, wired viaWithCollectibleAnalyzerReferences). Extending it to add-ins and per-recompile artifacts makes the accumulation collectible. - Gate workspace recompiles on a connected consumer.
FileSystemObservertriggers recompiles regardless of whether an app or IDE channel is attached. Suspending the watch session while no client is connected (and re-baselining on reconnect) eliminates the no-consumer growth entirely. - Recycle or bound the workspace. Dispose and recreate the
HotReloadManager/MSBuildWorkspaceafter N recompiles or beyond a memory threshold, so retained Roslyn state (generatorIStateTables in particular) has a lifetime. - Reconsider
System.GC.Server: truefor a long-lived background tool, or setSystem.GC.Conserve/a heap hard limit. Sinceruntimeconfig.jsonoverrides the environment, users currently have no way to opt out. - Align add-in TFMs.
Uno.UI.App.Mcp.Server1.2.44 references9.0.0.0framework assemblies against the .NET 10 host, producing 24AssemblyHelperbridge warnings at startup and 706FileNotFoundExceptions (resolver probing) over a 19-minute window.
How to reproduce it (as minimally and precisely as possible) 🔬
dotnet new unoapp -o LeakRepro -preset recommended, pinUno.Sdk6.6.42, keep onlynet10.0-desktop.- Start a DevServer for it and connect an app/IDE so the hot-reload workspace initializes (
ConfigureServerreceived, workspace loaded). - Attach
dotnet-counters monitor -p <pid> --counters System.Runtimeand watchdotnet.assembly.countand working set. - Leave everything idle 10 minutes: both stay flat.
- Edit and rebuild the watched solution in a loop: assembly count climbs monotonically and private bytes grow by roughly 100 to 470 MB per edit/build episode. Disconnect the app; growth continues on further edits.
- Kill and restart the DevServer: it returns to ~35 MB, then re-climbs with the same slope. (This reset-and-re-climb is why the curve looks like a leak rather than a steady state.)
Workaround 🛠️
- Kill
Uno.UI.RemoteControl.Hostprocesses between work sessions; they survive their app and keep recompiling on edits. - Set the Windows pagefile to system-managed so commit exhaustion degrades to slowdown instead of app terminations.
Renderer 🎨
Skia
Affected platforms 📱💻🖥️
Windows (net10.0-desktop); the mechanism is platform-agnostic.
Uno.Sdk version (and other relevant versions) 📦
- Uno.WinUI.DevServer 6.6.184 (host: net10.0,
System.GC.Server: truein runtimeconfig) - Uno.Sdk 6.6.42 (stable) for the repro app
- Uno.UI.App.Mcp 1.2.44 (references 9.0.0.0 assemblies against the .NET 10 host)
- .NET 10, Windows 11 Pro 26200, 16 cores, 31.6 GB RAM
IDE version 🧑💻
None attached (agent/MCP-driven DevServer; uno-devserver list reports IDE Channel: <none>). The growth reproduces with no IDE and no app connected.
Anything else we need to know? 💬
Raw evidence available on request: 15 s process sampling CSV, dotnet-counters System.Runtime CSV (5 s interval, 19 min), a 241 MB gcdump plus its type report, all-thread managed stacks, and the full host startup log with the 24 add-in bridge warnings.
Activity
noknowscode commentedon Aug 20, 2026
Verified still present in latest dev (decompiled DevServer 6.8.0-dev.46 + Uno.UI.App.Mcp 1.4.0-dev.1, pinned by Uno.Sdk 6.8.0-dev.21):
Assembly.LoadFrominto the default ALC, ungatedFileSystemObserver,System.GC.Server: true, and the App.Mcp add-in still targets net9.0 against the net10 host. Related: #23863 already introducedCollectibleAnalyzerAssemblyLoaderin this component.Fix proposals, in leverage order:
BufferGateand the startup path already cover this). Removes the compile-for-nobody growth (100–470 MB per edit cycle, measured).InitializeInneragain. Bounds the retained Roslyn state at the cost of one EnC re-baseline.Unload()+ one compacting gen2 collect, verified viaWeakReference. Depends on 4: collectible ALCs only die when gen2 runs.GCHeapHardLimitPercent. Measured on 16 cores: 1 gen2 collection in 19 min; a forced GC reclaimed ~1 GB.runtimeconfig.jsonoverridesDOTNET_gcServer, so users cannot opt out today.Default.Resolvingbridge warnings.If only one lands short-term: #1. Smallest diff, eliminates the forgotten-DevServer scenario.
Raw captures (sampling CSVs, counters, gcdump, stacks, host log) available on request.
dr1rrb commentedon Aug 25, 2026
Investigation update
Thanks for the extra detail and the second report bundle — the clarification changes the framing, so here is a summary for anyone following, plus where our investigation currently stands.
Corrected repro (from the reporter's clarification)
The earlier "no app and no IDE connected" wording was misleading. The actual sequence is:
Minimal repro: launch the app once → close it → keep editing and rebuilding. No app/IDE is connected at the time of the leak, but one connected earlier to initialize the workspace, and the DevServer never tore it down.
Where the growth actually comes from
We chased the three compounding factors in the report and can now separate them:
AssemblyHelper.Loadruns once at startup (add-in discovery), not per recompile.CollectibleAnalyzerAssemblyLoader's per-directory contexts are genuinely collectible — an unrootedDirectoryLoadContextis reclaimed by the GC on its own. They only survive because the long-lived workspace keeps them rooted; they are a passenger, not the engine.WatchHotReloadService→ Roslyn'sUnitTestingHotReloadService), Roslyn'sDebuggingSessionaccumulates oneProjectBaselineper committed hot-reload generation (_projectBaselines, appended inCommitSolutionUpdate). EachProjectBaseline→EmitBaselineretains that generation'sCompilationplus its added-metadata maps (TypesAdded/MethodsAdded/FieldsAdded/AddedOrChangedMethods, IL + metadata), chained by generation ordinal. So the retained state is O(number of committed generations) for the whole lifetime of the session — unbounded across a working day.Reproduced and measured
Driving the real EnC session over 400 valid hot-reload generations, holding only the session (no solution retained by the test harness), rooted memory — survivors after a forced blocking gen2 GC — grows linearly from ~10 MB to ~130 MB (~0.3 MB/generation), with no plateau. The retained heap is dominated by
Microsoft.CodeAnalysis: syntax caches (TextKeyedCache/GreenNode[]), symbols, incremental-generatorNodeStateTableentries, and the retainedCompilations — the same signature as the gcdump in the report. WithSystem.GC.Server: true, gen2 collections do not fire under commit pressure, so the process keeps growing until the OS commit limit is reached (the forced GC that gcdump triggers reclaims a large chunk instantly).The absolute per-generation cost in our minimal harness is small; in a real Uno app it is much larger (the source generators emit substantial state per generation), which is consistent with the hundreds-of-MB-per-edit numbers in the report.
Why it persists with the app closed
The workspace / EnC session lifetime is tied to the DevServer (reused across launches, outlives the app), not to the running app.
FileSystemObserverkeeps recompiling on every edit with no "is a consumer still attached?" gate, and every committed generation is retained by the EnC debugging session.Fix directions (EnC-cumulativity aware)
The baseline chain is required to emit correct subsequent deltas, so it cannot simply be dropped mid-session. The tractable levers:
System.GC.Serverfor a long-lived background broker (or set a heap hard limit /GCConserveMemory), since it currently hides the growth until the OS reacts.We are validating the consumer-gating fix next and will follow up.
fix(devserver): cap concurrent hot-reload workspaces, disable oldest …