Repository navigation
[Leak scan] Fix MauiHotReloadHelper.currentViews — disabled unregister leaves views rooted - #38657
Conversation
…r leaves views rooted
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 38657Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 38657" |
|
Hey there @@SubhikshaSf4851! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
|
Warning Your |
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
|
/azp run maui-pr-uitests , maui-pr-devicetests |
|
Azure Pipelines: Successfully started running 2 pipeline(s). |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
This comment has been minimized.
This comment has been minimized.
|
Note 🔍
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The regression test may silently pass without metadata-update support, and its scenario comment is stale.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
Fixes a Hot Reload memory leak by ensuring registered views are removed when Hot Reload is disabled.
Changes:
- Updates
UnRegisterto always clean up registered views. - Adds GC-based leak regression coverage.
- The test requires explicit metadata-update support and has a stale scenario comment.
| File | Description |
|---|---|
src/Core/src/HotReload/HotReloadHelper.cs |
Ensures disabled Hot Reload still unregisters views. |
src/Controls/tests/Core.UnitTests/HotReloadLeakTest.cs |
Adds leak regression scenarios. |
| MauiHotReloadHelper.IsEnabled = true; | ||
|
|
||
| for (var i = 0; i < N; i++) | ||
| { | ||
| var payload = new byte[1024 * 1024]; | ||
| var view = new ContentView(); | ||
| view.SetValue(PayloadProperty, payload); | ||
|
|
||
| if (mode != Mode.Control) | ||
| MauiHotReloadHelper.Register(view); |
| if (mode == Mode.Leaky) | ||
| { | ||
| MauiHotReloadHelper.IsEnabled = false; | ||
| MauiHotReloadHelper.UnRegister(view); // Returns without removing the view. |
MauiBot
left a comment
There was a problem hiding this comment.
Expert Review — 1 findings
See inline comments for details.
| for (var i = 0; i < N; i++) | ||
| { | ||
| var payload = new byte[1024 * 1024]; | ||
| var view = new ContentView(); |
There was a problem hiding this comment.
🔍 AI-Generated Review (multi-model)
[major] Regression Prevention and Test Coverage — The test never verifies the Hot Reload precondition that reproduces the leak path (MetadataUpdater.IsSupported/modifiable assemblies). In the ordinary CI environment where Register/UnRegister are no-ops, this still passes before and after the fix, so it cannot detect regression of the reported leak scenario.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@SubhikshaSf4851 — new AI review results are available based on commit
5a02f0f.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ❌ FAILED
Platform: ANDROID · Base: main · Merge base: 828569a8
🩺 Test does not reproduce the bug — ran the same in both states (PASS without fix, PASS with fix). The repro test is not exercising the issue. Strengthen the test before reviewing the fix.
| Test | Without Fix (expect FAIL) | With Fix (expect PASS) |
|---|---|---|
🧪 HotReloadLeakTest HotReloadLeakTest |
❌ PASS — 149s | ✅ PASS — 26s |
🔴 Without fix — 🧪 HotReloadLeakTest: PASS ❌ · 149s
(no coded error found; showing last 1200 chars)
c/Controls.Maps.csproj (in 85 ms).
Restored /home/vsts/work/1/s/src/Essentials/src/Essentials.csproj (in 10 ms).
Restored /home/vsts/work/1/s/src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj (in 2.55 sec).
Restored /home/vsts/work/1/s/src/Core/src/Core.csproj (in 26 ms).
Restored /home/vsts/work/1/s/src/Core/maps/src/Maps.csproj (in 22 ms).
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.2 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.19] Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.65] Discovered: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.66] Starting: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:01.87] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed HotReloadLeakTest.MauiHotReloadHelper_CurrentViews_Leaks [146 ms]
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 2.4469 Seconds
🟢 With fix — 🧪 HotReloadLeakTest: PASS ✅ · 26s
Determining projects to restore...
All projects are up-to-date for restore.
Test run for /home/vsts/work/1/s/artifacts/bin/Controls.Core.UnitTests/Debug/net10.0/Microsoft.Maui.Controls.Core.UnitTests.dll (.NETCoreApp,Version=v10.0)
VSTest version 18.0.2 (x64)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.2+699d445a1a (64-bit .NET 10.0.13)
[xUnit.net 00:00:00.33] Discovering: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:03.25] Discovered: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:03.28] Starting: Microsoft.Maui.Controls.Core.UnitTests
[xUnit.net 00:00:03.60] Finished: Microsoft.Maui.Controls.Core.UnitTests
Passed HotReloadLeakTest.MauiHotReloadHelper_CurrentViews_Leaks [245 ms]
Test Run Successful.
Total tests: 1
Passed: 1
Total time: 4.7265 Seconds
⚠️ Failure Details
- ❌ HotReloadLeakTest PASSED without fix (should fail) — tests don't catch the bug
📁 Fix files reverted (1 files)
src/Core/src/HotReload/HotReloadHelper.cs
📋 Pre-Flight — Context & Validation
PR #38657 Pre-Flight
Context
- PR:
[Leak scan] Fix MauiHotReloadHelper.currentViews — disabled unregister leaves views rooted - Issue: #38351
- Base:
main - Materialized merge base:
828569a86489228dc66a7867173635a6fb4f27be - Materialized PR commit:
4e819e30f327c4133eafdbc712a46d0a4195b7a4 - Target platform: Android (the affected implementation and primary test are cross-platform managed code)
MauiHotReloadHelper.Register stores each enabled, supported IHotReloadableView as a strong key in the process-wide currentViews dictionary. In the base implementation, UnRegister returns when IsEnabled is false, so a view registered while Hot Reload is enabled remains rooted if Hot Reload is disabled before teardown. The retained view keeps its object graph alive.
PR Diff
The PR changes two files:
src/Core/src/HotReload/HotReloadHelper.cs- Removes the
if (!IsEnabled) return;guard fromUnRegister. - Existing approach: permit cleanup regardless of the current enabled state.
- Removes the
src/Controls/tests/Core.UnitTests/HotReloadLeakTest.cs- Adds
MauiHotReloadHelper_CurrentViews_Leaks, covering unregistered control, unregister-while-disabled, and unregister-while-enabled cases with weak payload references.
- Adds
The only production file eligible for try-fix modification is src/Core/src/HotReload/HotReloadHelper.cs. The new test file is test input and must not be edited.
Gate Evidence
The completed gate failed because HotReloadLeakTest passed both without and with the PR fix. The base implementation exits from both Register and UnRegister when MetadataUpdater.IsSupported is false, so nothing is inserted and the test cannot observe the leak under the gate's default process environment. Issue #38351's standalone reproducer explicitly used DOTNET_MODIFIABLE_ASSEMBLIES=debug; the gate did not.
Do not rerun gate verification. For each candidate, run only the primary test with metadata updates enabled:
DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReloadLeakTest.MauiHotReloadHelper_CurrentViews_Leaks"There are no separately enumerated mandatory regression tests in the STEP 5a request. Do not run a full suite.
Alternative-Fix Boundary
Each candidate must differ at the mechanism/root-cause level from the PR's direct removal of the IsEnabled guard in UnRegister. Candidate 2 must also avoid candidate 1's recorded mechanism. Each attempt gets one implementation/test pass and at most one focused correction/retest, must perform the try-fix skill's inline expert self-review, capture its diff and test output, and restore through EstablishBrokenBaseline.ps1 -Restore.
Existing Evidence
- Regression cross-reference: no overlap with labeled bug-fix PRs touching the modified files in the last six months.
- Detected unrelated UI-test categories:
Button,Label,Layout; they are not part of this unit-test-only STEP 5a. - GitHub CLI authentication was unavailable; public GitHub API context and the locally materialized PR diff were used instead.
🔬 Code Review — Deep Analysis
Expert Evaluation — Raw PR
Verdict: NEEDS_CHANGES
Confidence: high
The production change is a focused and appropriate cleanup fix: Register can add a strong currentViews entry only while Hot Reload is enabled, while UnRegister now removes that entry regardless of the later enabled state. This preserves registration and replacement semantics and makes teardown symmetric across the enabled-to-disabled transition.
Actionable Finding
- [major] Regression Prevention and Test Coverage —
src/Controls/tests/Core.UnitTests/HotReloadLeakTest.cs:58: The regression test does not establish thatMetadataUpdater.IsSupportedis true. In an ordinary test process where modifiable assemblies are not enabled,RegisterandUnRegisterare both no-ops, so all weak references are collected and the test passes with or without the production fix. The trusted Gate observed exactly this false-green behavior.
Required Refinement
Make the test fail explicitly when its Hot Reload precondition is unavailable rather than silently exercising no-op paths. The focused validation must run with DOTNET_MODIFIABLE_ASSEMBLIES=debug, which makes the test exercise registration and demonstrates the submitted cleanup behavior.
Scope and Risk
The shared static registry affects all platforms, but the production diff only removes an obsolete cleanup veto and introduces no new state, allocation, public API, or platform-specific behavior. The blocking issue is the nondiscriminating regression test, not the cleanup mechanism.
🛠️ Try-Fix — Analysis & Comparison
PR #38657 Try-Fix Aggregate
Bounded STEP 5a alternatives: maximum two candidates, executed sequentially. The PR's existing approach (remove the IsEnabled guard from UnRegister) is excluded from both candidates.
Candidate 1 — Clear Registrations on Disable
Model: gpt-5.3-codex
Result: Pass
Self-review: 0 findings
Correction/retest used: No
Approach
Replace the IsEnabled auto-property with a backing-field property that clears currentViews when Hot Reload transitions from enabled to disabled.
Mechanism-Level Difference
The PR defers cleanup until each view reaches UnRegister and makes that cleanup independent of the current enabled state. Candidate 1 instead makes the enabled-to-disabled transition itself the cleanup boundary: all registrations are released immediately, so later disabled teardown cannot encounter a retained entry.
Diff
diff --git a/src/Core/src/HotReload/HotReloadHelper.cs b/src/Core/src/HotReload/HotReloadHelper.cs
index 2049cea704..5cd25ad527 100644
--- a/src/Core/src/HotReload/HotReloadHelper.cs
+++ b/src/Core/src/HotReload/HotReloadHelper.cs
@@ -23,7 +23,21 @@ namespace Microsoft.Maui.HotReload
{
replacedViews.Clear();
}
- public static bool IsEnabled { get; set; } = Debugger.IsAttached;
+ static bool _isEnabled = Debugger.IsAttached;
+ public static bool IsEnabled
+ {
+ get => _isEnabled;
+ set
+ {
+ if (_isEnabled == value)
+ return;
+
+ _isEnabled = value;
+
+ if (!_isEnabled)
+ currentViews.Clear();
+ }
+ }
internal static bool IsSupported
#if !NETSTANDARDTest
DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReloadLeakTest.MauiHotReloadHelper_CurrentViews_Leaks"Result: Failed: 0, Passed: 1, Skipped: 0, Total: 1 (132 ms test duration). No correction/retest was needed.
Analysis
Clearing currentViews on the enabled-to-disabled transition removes the strong references created while Hot Reload was enabled. The targeted leak test therefore passes even though the base UnRegister method still short-circuits while disabled. This is broader than the PR fix because disabling Hot Reload drops every current registration at once; STEP 5b should decide whether that lifecycle behavior is acceptable when Hot Reload is later re-enabled.
Restoration completed with Restored True.
Artifacts: CustomAgentLogsTmp/PRState/38657/PRAgent/try-fix/attempt-1/ and CustomAgentLogsTmp/PRState/38657/PRAgent/try-fix-1/content.md.
Candidate 2 — Weak-Key Registration Storage
Model: gpt-5.6-sol
Result: Pass
Self-review: 0 findings
Correction/retest used: No
Approach
Replace the strong-keyed Dictionary<IHotReloadableView, object[]> registry with a ConditionalWeakTable<IHotReloadableView, object[]>. Registration removes any existing association before adding the latest constructor parameters, preserving per-view replacement data without making the process-wide registry own the view's lifetime.
Mechanism-Level Difference
The PR keeps strong ownership and changes disabled teardown so UnRegister removes each entry. Candidate 1 also keeps strong ownership but clears all entries when Hot Reload is disabled. Candidate 2 changes neither UnRegister nor IsEnabled; it addresses registry ownership itself. The association remains available while a view is live, but the weak key cannot retain an otherwise unreachable view or its associated parameters.
Diff
diff --git a/src/Core/src/HotReload/HotReloadHelper.cs b/src/Core/src/HotReload/HotReloadHelper.cs
index 2049cea704..e5de3a4294 100644
--- a/src/Core/src/HotReload/HotReloadHelper.cs
+++ b/src/Core/src/HotReload/HotReloadHelper.cs
@@ -5,6 +5,7 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
+using System.Runtime.CompilerServices;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Hosting;
@@ -41,7 +42,8 @@ namespace Microsoft.Maui.HotReload
if (!IsEnabled)
return;
- currentViews[view] = parameters;
+ currentViews.Remove(view);
+ currentViews.Add(view, parameters);
}
public static void UnRegister(IHotReloadableView view)
@@ -115,7 +117,7 @@ namespace Microsoft.Maui.HotReload
static internal readonly WeakList<IHotReloadableView> ActiveViews = new WeakList<IHotReloadableView>();
static Dictionary<string, Type> replacedViews = new(StringComparer.Ordinal);
- static Dictionary<IHotReloadableView, object[]> currentViews = new Dictionary<IHotReloadableView, object[]>();
+ static ConditionalWeakTable<IHotReloadableView, object[]> currentViews = new ConditionalWeakTable<IHotReloadableView, object[]>();
static Dictionary<string, List<KeyValuePair<Type, Type>>> replacedHandlers = new(StringComparer.Ordinal);
[RequiresUnreferencedCode("Hot Reload is not trim compatible")]Test
DOTNET_MODIFIABLE_ASSEMBLIES=debug dotnet test src/Controls/tests/Core.UnitTests/Controls.Core.UnitTests.csproj --filter "FullyQualifiedName~HotReloadLeakTest.MauiHotReloadHelper_CurrentViews_Leaks"Result: Failed: 0, Passed: 1, Skipped: 0, Total: 1 (231 ms test duration). No correction/retest was needed.
Analysis
ConditionalWeakTable preserves constructor parameters for live registered views while allowing an otherwise unreachable view and its dependent value graph to be collected. The targeted test proves collectibility for the enabled-register/disabled-unregister sequence. This is a broader ownership-model change than the PR and should receive API/runtime compatibility scrutiny in STEP 5b, particularly around registration replacement semantics and supported target frameworks.
Restoration completed with Restored True.
Artifacts: CustomAgentLogsTmp/PRState/38657/PRAgent/try-fix/attempt-2/ and CustomAgentLogsTmp/PRState/38657/PRAgent/try-fix-2/content.md.
Aggregate Outcome
Both bounded alternatives passed the single detected primary test on their first test run, with no focused correction, no extra test suite, and clean inline expert self-reviews. Candidate 1 changes lifecycle semantics by dropping all registrations at disable-time; candidate 2 changes ownership semantics by making registrations weak-keyed. These are evidence-bearing alternatives for STEP 5b, not changes applied to the PR branch.
📝 PR Finalize — Recommended Title & Description
Assessment: ✏️ Recommend updating — the current metadata is accurate at a high level, but the title uses a workflow label instead of the component-oriented prefix and the description omits the precise enabled-state root cause and Hot Reload test prerequisite.
Recommended title
[Core] MauiHotReloadHelper: Remove currentViews entries when unregistering while disabled
Recommended description
This pull request fixes a memory leak in the Hot Reload view registry and adds a focused regression test.
### Root Cause
`MauiHotReloadHelper.Register` adds supported views to the process-wide `currentViews` dictionary while Hot Reload is enabled. If Hot Reload is then disabled before teardown, `UnRegister` returns early and leaves the view as a strong dictionary key, retaining the view and its object graph.
### Description of Change
**Hot Reload system behavior:**
* Updated `MauiHotReloadHelper.UnRegister` in `HotReloadHelper.cs` to remove the view from `currentViews` regardless of the current `IsEnabled` value. The existing `IsSupported` guard remains in place.
**Testing and memory management improvements:**
* Added `MauiHotReloadHelper_CurrentViews_Leaks` in `HotReloadLeakTest.cs`.
* The test uses weak payload references to cover an unregistered control, unregistering while Hot Reload is disabled, and unregistering while Hot Reload is enabled.
* The Hot Reload path requires the test process to run with `DOTNET_MODIFIABLE_ASSEMBLIES=debug`.
### Issues Fixed
Fixes #38351
### Tested the behavior in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac
| Before Issue Fix | After Issue Fix |
|----------|----------|
| <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> |
🏁 Report — Final Recommendation
⚠️ Final Recommendation: REQUEST CHANGES
Winner: pr-plus-reviewer
pr-plus-reviewer is the strongest candidate because it retains the submitted PR's minimal, behaviorally precise production fix and resolves the expert review's concrete test-validity defect. With metadata updates enabled, its focused regression test passed (1/1); without Hot Reload support, the test now reports a skip instead of a false pass.
Comparative Ranking
| Rank | Candidate | Regression evidence | Assessment |
|---|---|---|---|
| 1 | pr-plus-reviewer |
Pass: 1 passed, 0 failed, 0 skipped with DOTNET_MODIFIABLE_ASSEMBLIES=debug |
Keeps cleanup localized to UnRegister, preserves current registration/re-enable semantics, and explicitly distinguishes an unsupported test environment from a passing regression. |
| 2 | try-fix-2 |
Pass: 1 passed, 0 failed | ConditionalWeakTable addresses the ownership root cause and avoids retaining abandoned views, but it is a broader storage-model change and leaves the submitted test capable of falsely passing when metadata updates are unsupported. |
| 3 | try-fix-1 |
Pass: 1 passed, 0 failed | Clearing currentViews on every enabled-to-disabled transition fixes the leak, but changes lifecycle semantics for all live registrations; re-enabling Hot Reload can lose constructor parameters that were intentionally registered for still-live views. It also leaves the unsupported-environment false pass unresolved. |
| 4 | pr |
Trusted Gate failed: the test passed both without and with the production fix | The production cleanup is sound and minimal, but the raw test does not prove it: when MetadataUpdater.IsSupported is false, both relevant methods are no-ops and the assertions pass without exercising currentViews. Per the failed Gate and expert [major] finding, the raw submission cannot win. |
Expert Review Reconciliation
The sole inline finding is actionable and blocking for approval: HotReloadLeakTest.cs does not establish its Hot Reload prerequisite. The winning candidate addresses exactly that issue without modifying the production mechanism or broadening runtime behavior.
Required PR Change
Apply pr-plus-reviewer/reviewer.patch to the submitted PR. No further repair iteration or broader suite is recommended by this review; the required focused validation already passed once.
📱 UI Tests — Button,Label,Layout
Detected UI test categories: Button,Label,Layout
✅ Deep UI tests — 422 passed, 0 failed, 7 skipped across 3 categories on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
Button |
104/106 (2 skipped) ✓ | — |
Label |
123/125 (2 skipped) ✓ | — |
Layout |
195/198 (3 skipped) ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
🧭 Next Steps — reviewer changes required
The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.
Why: The reviewer-refined PR preserves the submitted fix's narrow unregister cleanup semantics while preventing the regression test from falsely passing when Hot Reload is unsupported. Its required focused test passed with metadata updates enabled, whereas the raw PR failed the trusted Gate's test-validity requirement.
Address the actionable findings in this review before merging.
…r leaves views rooted (#38657) <!-- Please keep the note below for people who find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment whether this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the `UnRegister` method to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained. ### Description of Change **Hot reload system behavior:** * Updated the `UnRegister` method in `HotReloadHelper.cs` to always remove the view from `currentViews`, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled. **Testing and memory management improvements:** * Added a new test `HotReloadLeakTest` in `HotReloadLeakTest.cs` to verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38351 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…r leaves views rooted (#38657) <!-- Please keep the note below for people who find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment whether this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the `UnRegister` method to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained. ### Description of Change **Hot reload system behavior:** * Updated the `UnRegister` method in `HotReloadHelper.cs` to always remove the view from `currentViews`, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled. **Testing and memory management improvements:** * Added a new test `HotReloadLeakTest` in `HotReloadLeakTest.cs` to verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38351 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…r leaves views rooted (#38657) <!-- Please keep the note below for people who find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment whether this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the `UnRegister` method to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained. ### Description of Change **Hot reload system behavior:** * Updated the `UnRegister` method in `HotReloadHelper.cs` to always remove the view from `currentViews`, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled. **Testing and memory management improvements:** * Added a new test `HotReloadLeakTest` in `HotReloadLeakTest.cs` to verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38351 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…r leaves views rooted (#38657) <!-- Please keep the note below for people who find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment whether this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the `UnRegister` method to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained. ### Description of Change **Hot reload system behavior:** * Updated the `UnRegister` method in `HotReloadHelper.cs` to always remove the view from `currentViews`, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled. **Testing and memory management improvements:** * Added a new test `HotReloadLeakTest` in `HotReloadLeakTest.cs` to verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38351 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…r leaves views rooted (#38657) <!-- Please keep the note below for people who find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment whether this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the `UnRegister` method to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained. ### Description of Change **Hot reload system behavior:** * Updated the `UnRegister` method in `HotReloadHelper.cs` to always remove the view from `currentViews`, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled. **Testing and memory management improvements:** * Added a new test `HotReloadLeakTest` in `HotReloadLeakTest.cs` to verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38351 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…r leaves views rooted (#38657) <!-- Please keep the note below for people who find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment whether this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the `UnRegister` method to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained. ### Description of Change **Hot reload system behavior:** * Updated the `UnRegister` method in `HotReloadHelper.cs` to always remove the view from `currentViews`, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled. **Testing and memory management improvements:** * Added a new test `HotReloadLeakTest` in `HotReloadLeakTest.cs` to verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38351 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->
…r leaves views rooted (#38657) <!-- Please keep the note below for people who find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment whether this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the `UnRegister` method to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained. ### Description of Change **Hot reload system behavior:** * Updated the `UnRegister` method in `HotReloadHelper.cs` to always remove the view from `currentViews`, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled. **Testing and memory management improvements:** * Added a new test `HotReloadLeakTest` in `HotReloadLeakTest.cs` to verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios. <!-- Enter description of the fix in this section --> ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #38351 ### Tested the behavior in the following platforms - [x] Windows - [x] Android - [x] iOS - [x] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="725" height="400" alt="Screenshot 2026-09-18 at 16 23 38" src="https://github.com/user-attachments/assets/c3d87ded-eaf2-4f22-9e2a-cb4ca23e2c84" /> | <img width="716" height="308" alt="Screenshot 2026-09-18 at 16 22 56" src="https://github.com/user-attachments/assets/69c362a3-eeaa-433d-8319-6ead28502606" /> | <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. -->


Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment whether this change resolves your issue. Thank you!
This pull request introduces a new unit test to detect and prevent memory leaks in the hot reload system, and it also updates the logic in the
UnRegistermethod to ensure proper cleanup of registered views, even when hot reload is disabled. These changes help ensure that memory is managed correctly during hot reload operations and that no unnecessary references are retained.Description of Change
Hot reload system behavior:
UnRegistermethod inHotReloadHelper.csto always remove the view fromcurrentViews, regardless of whether hot reload is enabled, preventing potential memory leaks when unregistering views while hot reload is disabled.Testing and memory management improvements:
HotReloadLeakTestinHotReloadLeakTest.csto verify that the hot reload system does not leak memory by retaining references to payloads after views are unregistered, covering control, leaky, and mitigation scenarios.Issues Fixed
Fixes #38351
Tested the behavior in the following platforms