Skip to content

Memory leak Device.Test pass with false positive #35485

Description

@pictos

Description

During some contributions, I figured out that memory leak unit tests are passing even if a memory leak happens. It can introduce bugs and a false security sensation.

I did create a test that will fail, and it passes even if there's a leak.

Image

Steps to Reproduce

Add this test method inside the Controls.DeviceTests

	[Fact]
	public async Task FailIfLeak()
	{
		var page = new ContentPage { Title = "Page 1" };

		await CreateHandlerAndAddToWindow(new Window(page), async () =>
		{
			await OnLoadedAsync(page);

		});

		await AssertionExtensions.WaitForGC(new WeakReference(page));

		GC.KeepAlive(page);
	}

Run it and see the success message.

Link to public reproduction project repository

https://github.com/pictos/maui/tree/pj/device-test-fail

Version with bug

10.0.60

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Windows, Android, iOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-lifecycleXPlat and Native UIApplicationDelegate/Activity/Window lifecycle eventsperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)platform/androidplatform/iosplatform/macosmacOS / Mac Catalystplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions