Repository navigation
[Windows]Fix and Re-enable "Handler Does Not Leak" Device Tests for HybridWebView - #36742
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36742Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36742" |
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
|
/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.
MauiBot
left a comment
There was a problem hiding this comment.
AI Review Summary
@BagavathiPerumal — new AI review results are available based on this last commit:
4ddbfc6.
🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix
Gate Result: ⚠️ INCONCLUSIVE
Platform: WINDOWS
⚠️ verify-tests-fail.ps1exited before writing a verification report. Diagnostics below.
Exit code: 3
Auto-detected:
- Test filter:
MemoryTests
Likely cause:
- No fix files detected in the diff (PR may be test-only — should now run in failure-only mode).
Artifacts written before exit:
verification-log.txt(0.2 KB)
Gate output log (last 60 lines)
📁 Output directory: CustomAgentLogsTmp/PRState/36742/PRAgent/gate/verify-tests-fail
🔍 Detecting base branch and merge point...
✅ Resolved PR #36742 base branch: main (fetched origin/main)
✅ Base branch: main (via explicit)
✅ Merge base commit: ee21c935
╔═══════════════════════════════════════════════════════════╗
║ VERIFY FAILURE ONLY MODE ║
╠═══════════════════════════════════════════════════════════╣
║ No fix files detected - will only verify: ║
║ 1. Tests FAIL (proving they catch the bug) ║
║ ║
║ Use this mode when creating tests before writing a fix. ║
╚═══════════════════════════════════════════════════════════╝
🔍 Auto-detecting test filter from changed test files...
✅ Auto-detected 1 test(s):
📱 [DeviceTest] MemoryTests (filter: MemoryTests)
🧪 Running 1 test(s) (expecting them to FAIL)...
─────────────────────────────────────────────────
📱 Test 1/1: [DeviceTest] MemoryTests
🧪 Running device tests: Controls on windows
Filter: MemoryTests
═══════════════════════════════════════════════════════════
MAUI Device Tests Runner
═══════════════════════════════════════════════════════════
✓ dotnet found: D:\a\1\s/.dotnet\dotnet.exe
Project: Controls
Project Path: src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj
Platform: windows
Configuration: Debug
Test Filter: MemoryTests
═══════════════════════════════════════════════════════════
Building Controls Device Tests for windows
═══════════════════════════════════════════════════════════
Running: dotnet build src/Controls/tests/DeviceTests/Controls.DeviceTests.csproj -c Debug -f net10.0-windows10.0.19041.0 /p:TreatWarningsAsErrors=false /p:RuntimeIdentifierOverride=win-x64 /p:WindowsPackageType=None /p:SelfContained=true /p:_MauiDeviceTestUnpackaged=true /p:UseMonoRuntime=false
✓ Build succeeded
✓ App found: D:\a\1\s\artifacts\bin\Controls.DeviceTests\Debug\net10.0-windows10.0.19041.0\win-x64\Microsoft.Maui.Controls.DeviceTests.exe
═══════════════════════════════════════════════════════════
Running Tests
═══════════════════════════════════════════════════════════
Running Windows device test app directly...
This matches eng/devices/windows.cake and avoids VSTest/testhost for MAUI Windows device apps.
Discovering Windows device test categories...
�[31;1mException: �[0mD:\a\1\s\.github\skills\run-device-tests\scripts\Run-DeviceTests.ps1:557�[0m
�[31;1m�[0m�[36;1mLine |�[0m
�[31;1m�[0m�[36;1m�[36;1m 557 | �[0m �[36;1mthrow "Test filter '$TestFilter' matched 0 Windows device�[0m …�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m | �[31;1m ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m | �[31;1mTest filter 'MemoryTests' matched 0 Windows device test categories. Available categories: Dispatcher, Border,�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m | �[31;1mBoxView, Button, CarouselView, CheckBox, CollectionView, Compatibility, ContentView, MenuFlyout, DatePicker,�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m | �[31;1mEditor, Entry, FlyoutPage, Label, Frame, HybridWebView, Image, Layout, FlexLayout, ListView, Modal,�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m | �[31;1mNavigationPage, Page, Path, Picker, Behavior, RadioButton, RefreshView, ScrollView, SearchBar, Shape, Shell,�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m | �[31;1mTabbedPage, TemplatedView, Toolbar, View, VisualElement, VisualElementTree, WebView, Window, Mapper, Xaml,�[0m
�[31;1m�[0m�[36;1m�[36;1m�[0m�[36;1m�[0m�[36;1m�[31;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m�[31;1m�[36;1m | �[31;1mWindowOverlay, Memory, Lifecycle�[0m
📱 UI Tests — Button,Label,Layout
Detected UI test categories: Button,Label,Layout
✅ Deep UI tests — 351 passed, 0 failed across 3 categories on platform-pool agent (replaces in-process counts above).
🧪 UI Test Execution Results (deep, platform pool)
| Category | Tests | Snapshot diffs |
|---|---|---|
Button |
69/70 ✓ | — |
Label |
91/94 ✓ | — |
Layout |
191/195 ✓ | — |
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs) |
📋 Pre-Flight — Context & Validation
Issue: #35985 - [Testing] Re-enable Cells and Handler Memory Leak Device Tests for June 08 Candidate Branch
PR: #36742 - [Windows]Fix and Re-enable "Handler Does Not Leak" Device Tests for HybridWebView
Platforms Affected: Windows (PR target); linked issue also mentions iOS and macOS memory test failures
Files Changed: 1 implementation/test file, 0 separate test files
Key Findings
- PR changes only
src/Controls/tests/DeviceTests/Memory/MemoryTests.cs, re-enabling theHybridWebViewHandlerDoesNotLeakinline data on Windows. - PR replaces a fixed pre-handler delay with a post-handler
WebView2.EnsureCoreWebView2Async()wait forHybridWebViewon Windows. - PR also explicitly disconnects and nulls the child view handler for every
HandlerDoesNotLeakinline-data control, not justHybridWebView. - Linked issue #35985 tracks memory device-test failures after #35487, including Windows
Cells Do Not LeakandHandler Does Not Leak; PR #36742 narrows its validated fix to WindowsHybridWebView. - Gate result supplied by caller is inconclusive because tests could not be built/run; no gate verification was re-run during pre-flight.
Code Review Summary
Verdict: NEEDS_CHANGES
Confidence: low
Errors: 1 | Warnings: 1 | Suggestions: 0
Key code review findings:
- ✗
src/Controls/tests/DeviceTests/Memory/MemoryTests.cs:370— unconditionalDisconnectHandler()weakens the broad memory test contract for all controls, not just the WindowsHybridWebViewcase. - ⚠
src/Controls/tests/DeviceTests/Memory/MemoryTests.cs:363—viewHandler.PlatformViewcan fail with an opaqueNullReferenceException; use an explicit assertion/guard if handler creation failed.
Failure-mode probes:
- Non-
HybridWebViewcontrols now receive explicit disconnect, changing existing leak coverage for unrelated handlers. HybridWebViewinitialization in flight should be addressed by awaitingEnsureCoreWebView2Async()on Windows after handler creation.- Handler creation failure currently produces an opaque null dereference.
Blast radius: test-only, but the changed HandlerDoesNotLeak teardown path runs for every inline-data control in the theory.
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| PR | PR #36742 | Re-enable Windows HybridWebView, await WebView2 initialization after handler creation, then disconnect/null every child handler before GC assertion. |
⚠ INCONCLUSIVE (Gate) | src/Controls/tests/DeviceTests/Memory/MemoryTests.cs |
Original PR; review concern is broad unconditional teardown. |
🔬 Code Review — Deep Analysis
Code Review — PR #36742
Independent Assessment
What this changes: Re-enables HandlerDoesNotLeak for HybridWebView on Windows, waits for WebView2 initialization, and explicitly disconnects/nulls the child view handler before GC checks.
Inferred motivation: Avoid a false leak caused by async WebView2 initialization still holding references when GC assertions run.
Reconciliation with PR Narrative
Author claims: Fixes timing in the HybridWebView memory test and re-enables the Windows case.
Agreement/disagreement: The WebView2 await matches the claim. However, the PR also changes teardown behavior for every control covered by HandlerDoesNotLeak, not just HybridWebView.
Prior Review Reconciliation
No prior ❌ Error findings found. Queried review bodies, inline review comments, and PR issue comments.
Blast Radius Assessment
- Runs for all instances: Yes — unconditional handler disconnect runs for every
HandlerDoesNotLeakinline data case. - Startup impact: No — test-only change.
- Static/shared state: No.
CI Status
- Required-check result: unavailable via
gh pr checks --requiredbecauseghis unauthenticated. - Public check-run result: failing (
maui-pr,maui-pr-uitests, Build Analysis);maui-pr-devicetestsreports success. - Classification: main
maui-prsampled failure is infra-like simulator runtime timeout; UI failures remain undetermined. - Action taken: invoked
azdo-build-investigatorcontext and capped confidence low.
Findings
❌ Error — Unconditional disconnect weakens the memory test contract
src/Controls/tests/DeviceTests/Memory/MemoryTests.cs:370
The new DisconnectHandler() block runs for all 30+ control types, not only the HybridWebView Windows case. Existing memory tests in this area generally verify handlers/platform views become collectible when locals fall out of scope. This change makes the broad HandlerDoesNotLeak test assert a weaker condition: collectible after explicit disconnect. That can hide future leaks where a handler is only collectible because this test forcibly invoked teardown.
Scope the explicit disconnect to the case that needs deterministic WebView2 teardown, or split that behavior into a targeted test.
⚠️ Warning — Opaque null failure if handler creation fails
src/Controls/tests/DeviceTests/Memory/MemoryTests.cs:363
viewHandler is null-guarded for WebView2 probing, but then dereferenced directly via viewHandler.PlatformView. Prefer Assert.NotNull(viewHandler) before creating references so failures identify missing handler creation instead of throwing a less helpful NullReferenceException.
Failure-Mode Probing
- Non-HybridWebView controls: now receive explicit disconnect, changing existing coverage for unrelated handlers.
- HybridWebView initialization still in flight:
EnsureCoreWebView2Async()should address this on Windows. - Handler creation failure: currently produces an opaque NRE at
viewHandler.PlatformView.
Verdict: NEEDS_CHANGES
Confidence: low
Summary: The targeted WebView2 wait is reasonable, but the unconditional handler disconnect broadens the behavioral change and weakens memory-leak coverage for unrelated controls. CI is not clean/fully classifiable from available unauthenticated data.
🛠️ Fix — Analysis & Comparison
Fix Candidates
| # | Source | Approach | Test Result | Files Changed | Notes |
|---|---|---|---|---|---|
| 1 | try-fix | Wait for MAUI HybridWebView.WebViewInitialized in the broad theory and remove explicit handler teardown. |
❌ Fail | 1 file | Build succeeded, but Windows Memory result XML was empty/invalid. Event-only wait is not reliable enough in this path. |
| 2 | try-fix | Wait for Windows handler-owned MauiHybridWebView.WebViewReadyTask and scope disconnect/null to Windows HybridWebView only. |
⚠ Blocked | 1 file | Build succeeded with 0 warnings/errors, but the same empty/invalid Windows Memory XML prevented verification. |
| 3 | try-fix | Split Windows HybridWebView into a dedicated memory test with loaded-page lifecycle, WebViewsCollection, WebViewInitialized wait, and targeted teardown; restore broad theory passive-GC semantics. |
⚠ Blocked | 1 file | Build succeeded with 0 warnings/errors and expert self-review was clean. Best alternative on code merits, but local Windows runner remained blocked. |
| PR | PR #36742 | Re-enable Windows HybridWebView, await direct WebView2 initialization, then disconnect/null every handler in the broad HandlerDoesNotLeak theory. |
⚠ INCONCLUSIVE (Gate) | 1 file | Original PR; code review concern is weakened unrelated control leak coverage. |
Cross-Pollination
| Model | Round | New Ideas? | Details |
|---|---|---|---|
| maui-expert-reviewer | 2 | No | NO NEW IDEAS: credible alternatives are already covered; remaining options are minor lifecycle/wait/cleanup variations or test-isolation workarounds, not materially different fixes. |
Exhausted: Yes
Selected Fix: Candidate #3 — best unverified alternative. It is not demonstrably passing because the local Windows Memory device-test runner repeatedly produced empty/invalid XML for all tested candidates, but it best addresses the code-review concern by isolating Windows HybridWebView lifecycle teardown and preserving broad memory-test coverage for unrelated controls.
Test Environment Note
All three candidates encountered the same local Windows runner failure after successful build:
Windows device test result file 'artifacts\log\TestResults-Microsoft_Maui_Controls_DeviceTests_Memory.xml' is empty or not valid XML (the device-test app likely crashed or exited before writing results).
This prevents declaring any candidate as test-passing in this environment.
📝 Recommended PR Title & Description
Assessment: ✏️ Recommend updating — the current metadata describes the raw PR's EnsureCoreWebView2Async() and broad handler-disconnect approach, but the winning fix uses a dedicated Windows HybridWebView memory test with MAUI initialization and targeted teardown.
Recommended title
[Windows] HybridWebView: Re-enable handler leak test with dedicated lifecycle
Recommended description
### Issue Details
The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR https://github.com/dotnet/maui/pull/35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes.
This PR addresses the Windows `HybridWebView` case in `HandlerDoesNotLeak`.
### Root cause
The Windows `HybridWebView` memory test case was disabled because the shared `HandlerDoesNotLeak` theory could reach its weak-reference/GC assertions before the Windows WebView2-backed `HybridWebView` had completed its asynchronous MAUI initialization path. That made the test report a false leak while initialization work was still holding live references.
### Description of Change
The fix re-enables Windows `HybridWebView` handler leak coverage by moving that case out of the broad `HandlerDoesNotLeak` theory and into a dedicated Windows-only `HybridWebViewHandlerDoesNotLeak` test.
The dedicated test:
- creates a loaded page/window lifecycle for `HybridWebView`
- waits for MAUI's `HybridWebView.WebViewInitialized` signal instead of directly calling WebView2 initialization APIs
- captures weak references after initialization completes
- removes the `HybridWebView` from the layout/page
- disconnects and nulls only the `HybridWebView` handler before the GC assertion
- places the memory test class in `WebViewsCollection` on Windows so WebView2 configuration-sensitive tests run serially
The broad `HandlerDoesNotLeak` theory keeps its passive-GC semantics for other controls, so unrelated handler leak coverage is not weakened by explicit teardown added only for the Windows `HybridWebView` special case.
### Regression PR
PR https://github.com/dotnet/maui/pull/35487
### Issues Fixed
Fixes https://github.com/dotnet/maui/issues/35985
### Platforms Tested
- [x] Windows
- [ ] Android
- [ ] iOS
- [ ] Mac
### Output ScreenShot
**Issue Fix3 (Windows — Handler Does Not Leak / HybridWebView)**
|Platform|Before|After|
|--|--|--|
|Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> |
🏁 Report — Final Recommendation
Comparative Report — PR #36742
Candidates compared
| Rank | Candidate | Regression result | Code assessment |
|---|---|---|---|
| 1 | try-fix-3 |
⚠ Blocked / unverified | Best code shape. Splits Windows HybridWebView into a dedicated memory test, waits for normal MAUI initialization through WebViewInitialized after loaded-page lifecycle, uses targeted teardown only for this special case, and preserves the broad HandlerDoesNotLeak passive-GC contract for unrelated controls. Build succeeded with 0 warnings/errors; the Windows runner produced empty/invalid XML, same as other blocked candidates. |
| 2 | pr-plus-reviewer |
⚠ Unverified | Improves the PR by replacing bare EnsureCoreWebView2Async() with the handler-owned MauiHybridWebView.WebViewReadyTask path and adding explicit null diagnostics. Still keeps explicit disconnect/null for every control in the shared theory, which is broader than necessary and weakens unrelated leak coverage. |
| 3 | try-fix-2 |
⚠ Blocked / unverified | Also uses MauiHybridWebView.WebViewReadyTask and scopes teardown to Windows HybridWebView, preserving most broad-theory semantics. It is less isolated than try-fix-3 because HybridWebView still runs inside the broad theory rather than a WebView-serialized dedicated test. |
| 4 | pr |
⚠ Gate inconclusive | Re-enables the intended Windows row and tries to wait for initialization, but the expert reviewer found a major Windows correctness issue: calling bare EnsureCoreWebView2Async() can race/conflict with the handler's configured initialization. It also applies explicit teardown to all controls in the shared theory. |
| 5 | try-fix-1 |
❌ Fail | Preserves broad passive-GC semantics, but the event-only wait did not produce a usable Windows test result and was classified as failed. Per ranking rule, this must remain below non-failing/unverified candidates. |
Key decision points
- Regression evidence: No candidate has a confirmed passing regression run.
try-fix-1is the only candidate classified as failed, so it is ranked below all non-failing candidates. The PR gate and the other try-fix runs are inconclusive/blocked rather than failing. - Windows
HybridWebViewinitialization: The raw PR's directEnsureCoreWebView2Async()call is unsafe becauseHybridWebViewHandleralready initializes WebView2 with MAUI-specific environment/options.pr-plus-reviewerandtry-fix-2avoid this by awaitingMauiHybridWebView.WebViewReadyTask;try-fix-3avoids direct WebView2 initialization and waits through the MAUIWebViewInitializedpath inside a loaded lifecycle. - Memory-test contract preservation: The raw PR and
pr-plus-reviewerexplicitly disconnect every control's handler before GC, weakening the broadHandlerDoesNotLeakcoverage for unrelated controls.try-fix-2scopes teardown to WindowsHybridWebView;try-fix-3goes further by moving that special lifecycle into a dedicated Windows-only test. - Isolation: Existing HybridWebView/WebView device tests use
WebViewsCollectionbecause WebView2 configuration can vary poorly within one process.try-fix-3is the only candidate that serializes the memory test class with that collection on Windows.
Winner
Winner: try-fix-3
try-fix-3 is the strongest fix on code merits. It resolves the PR's WebView2 initialization race risk, avoids broadening deterministic teardown to unrelated controls, and isolates the special Windows HybridWebView lifecycle in a dedicated test. Its regression run is still unverified because the local Windows device-test runner produced empty/invalid XML after a clean build, but that is not a candidate-specific test failure and no other candidate has stronger passing evidence.
🧭 Next Steps — alternative fix proposed (try-fix-3)
Automated review — alternative fix proposed
The expert-reviewer evaluation compared the PR fix against automatically generated candidates and selected try-fix-3 as the strongest fix.
Why: try-fix-3 best preserves the original broad HandlerDoesNotLeak contract while isolating the Windows HybridWebView lifecycle into a dedicated test. It avoids the PR's bare WebView2 initialization race and scopes deterministic teardown to the special HybridWebView case; its run was blocked by the same empty Windows result XML environment issue seen across candidates, not by a candidate-specific regression failure.
Please consider applying the candidate diff below (or use it as guidance). Once you push an update, this workflow will re-trigger and re-evaluate.
Candidate diff (try-fix-3)
diff --git a/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs b/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
index 1c5166f630..98ff85a4fd 100644
--- a/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
+++ b/src/Controls/tests/DeviceTests/Memory/MemoryTests.cs
@@ -25,6 +25,9 @@ using Xunit.Sdk;
namespace Microsoft.Maui.DeviceTests.Memory;
[Category(TestCategory.Memory)]
+#if WINDOWS
+[Collection(WebViewsCollection)]
+#endif
public class MemoryTests : ControlsHandlerTestBase
{
// Subclasses used to enable memory tests for CV2 handlers
@@ -216,7 +219,7 @@ public class MemoryTests : ControlsHandlerTestBase
#pragma warning restore CS0618 // Type or member is obsolete
[InlineData(typeof(GraphicsView))]
[InlineData(typeof(Grid))]
-#if TESTS_FAILS_ON_WINDOWS //For more information, see: https://github.com/dotnet/maui/issues/35985
+#if !WINDOWS
[InlineData(typeof(HybridWebView))]
#endif
[InlineData(typeof(Image))]
@@ -345,14 +348,77 @@ public class MemoryTests : ControlsHandlerTestBase
}
#pragma warning restore CS0618 // Type or member is obsolete
var handler = CreateHandler<LayoutHandler>(layout);
+ var viewHandler = view.Handler;
+
viewReference = new WeakReference(view);
- handlerReference = new WeakReference(view.Handler);
- platformViewReference = new WeakReference(view.Handler.PlatformView);
+ handlerReference = new WeakReference(viewHandler);
+ platformViewReference = new WeakReference(viewHandler.PlatformView);
});
await AssertionExtensions.WaitForGC(viewReference, handlerReference, platformViewReference);
}
+#if WINDOWS
+ [Fact("HybridWebView Handler Does Not Leak")]
+ public async Task HybridWebViewHandlerDoesNotLeak()
+ {
+ SetupBuilder();
+
+ WeakReference viewReference = null;
+ WeakReference platformViewReference = null;
+ WeakReference handlerReference = null;
+
+ var page = new ContentPage();
+
+ await CreateHandlerAndAddToWindow<IWindowHandler>(new Window(page), async _ =>
+ {
+ var layout = new Grid();
+ var hybridWebView = new HybridWebView
+ {
+ HybridRoot = "HybridTestRoot"
+ };
+
+ var initialized = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
+ EventHandler<WebViewInitializedEventArgs> onInitialized = (_, _) => initialized.TrySetResult();
+ hybridWebView.WebViewInitialized += onInitialized;
+
+ try
+ {
+ layout.Add(hybridWebView);
+ page.Content = layout;
+
+ await OnLoadedAsync(hybridWebView);
+ await initialized.Task.WaitAsync(TimeSpan.FromSeconds(30));
+
+ var viewHandler = hybridWebView.Handler;
+ Assert.NotNull(viewHandler);
+ var platformView = viewHandler.PlatformView;
+ Assert.NotNull(platformView);
+
+ viewReference = new WeakReference(hybridWebView);
+ handlerReference = new WeakReference(viewHandler);
+ platformViewReference = new WeakReference(platformView);
+
+ layout.Remove(hybridWebView);
+ page.Content = null;
+
+ if (viewHandler is IViewHandler disconnectableHandler)
+ {
+ disconnectableHandler.DisconnectHandler();
+ }
+
+ hybridWebView.Handler = null;
+ }
+ finally
+ {
+ hybridWebView.WebViewInitialized -= onInitialized;
+ }
+ }, timeOut: TimeSpan.FromSeconds(45));
+
+ await AssertionExtensions.WaitForGC(viewReference, handlerReference, platformViewReference);
+ }
+#endif
+
[Theory("Polygon and Polyline Points Replacement Does Not Leak Handler")]
[InlineData(typeof(Polygon))]
[InlineData(typeof(Polyline))]
I've addressed the following concerns. Please find the below details for your reference.
|
|
Azure Pipelines: Successfully started running 1 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
This PR updates the Controls device-test memory leak validation to re-enable the HybridWebView case on Windows and to make the “Handler Does Not Leak” test more deterministic for WebView2-backed initialization.
Changes:
- Re-enabled the
HybridWebViewInlineDatafor the “Handler Does Not Leak” theory on Windows. - For Windows
HybridWebView, awaitsWebView2.EnsureCoreWebView2Async()after handler creation to avoid timing-based false leak reports. - Explicitly disconnects the
HybridWebViewhandler (Windows-only) before releasing the handler reference and forcing GC.
| bool isWindowsHybridWebView = false; | ||
|
|
||
| if (view is HybridWebView) | ||
| { | ||
| #if WINDOWS |
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
…ybridWebView (#36742) <!-- Please let the below note in for people that 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 if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issue Details The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes. ### Root cause The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now. ### Solution description The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection. Validated the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac ### Regression PR PR #35487 ### Issues Fixed Fixes #35985 ### Output ScreenShot **Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)** |Platform|Before|After| |--|--|--| |Windows|<video src="https://github.com/user-attachments/assets/4b0f6da1-28d1-4290-81a9-b9dd0f89ef09">|<video src="https://github.com/user-attachments/assets/bcc24ab4-7bab-44cd-a8d7-a9e4748373a7"> | --------- Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
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 if this change resolves your issue. Thank you!
Issue Details
The device memory leak validation tests began failing in the Candidate branch after the test-related changes introduced in PR #35487, which exposed actual memory leaks that were previously undetected. The regressions affected the Cells Do Not Leak and Handler Does Not Leak tests on Windows, the Cells Do Not Leak test on iOS, the Handler Does Not Leak test on iOS 26.0, and the Handler Does Not Leak test on macOS 26.0, indicating platform-specific memory leak issues that require fixes.
Root cause
The issue occurs because of a timing problem in the memory leak test itself, not a production defect. The test waited a fixed amount of time for the hybrid web view case before its handler (and therefore its underlying native web view) had even been created, so the platform's asynchronous initialization had no real opportunity to progress. By the time the test forced garbage collection and checked its weak references, that initialization was still in flight and holding a live reference, causing a false leak report. A related test guard had also excluded this case from running at all until now.
Solution description
The fix involves removing the guard so the case is actually exercised, and replacing the fixed delay with an explicit await on WebView2.EnsureCoreWebView2Async() , placed after the handler is created. This ensures the test only proceeds once initialization has genuinely completed (or immediately, if already done), removing any fixed-timeout guesswork. The test was also updated to explicitly disconnect each view's handler before checking for collection.
Validated the behavior in the following platforms
Regression PR
PR #35487
Issues Fixed
Fixes #35985
Output ScreenShot
Issue Fix3 (Windows — (Handler Does Not Leak) HybridWebView)
BeforeFix-HandlerDoesNotLeak-Windows.mp4
AfterFix-HandlerDoesNotLeak.Windows.1.1.mp4