Skip to content

Memory leak when closing BottomSheet #900

Description

@runefauske

Noticed a memory leak related to the BottomSheet component while running an app on Android. Even the built in memory toolkit reports this when DUI.IsDebug = true.

Using DIPS.Mobile.UI 60.2.14 and Microsoft.MAUI.Controls 10.0.71

How to reproduce:

var bottomSheet = new BottomSheet();
BottomSheetService.Open(bottomSheet);

Closing the sheet gives the following output:

06-15 14:25:13.371 I/DOTNET  (12889): GarbageCollection: 📈 GC Memory before: 7686656 byte (7.33 mb)
06-15 14:25:13.371 I/DOTNET  (12889): GarbageCollection: Checking 9 GC collections.
...
06-15 14:25:15.585 I/DOTNET  (12889): GarbageCollection: Number of leaks: 1
06-15 14:25:15.585 I/DOTNET  (12889): GarbageCollection: ---- Visual children zombies of BottomSheet: ----
06-15 14:25:15.587 I/DOTNET  (12889): GarbageCollection: - 🧟 DIPS.Mobile.UI.Components.BottomSheets.BottomSheet is a zombie!
06-15 14:25:15.588 I/DOTNET  (12889): GarbageCollection: 📈 GC Memory after: 6599416 byte (6.29 mb), difference: 1087240 bytes (1.04 mb)
06-15 14:25:15.592 I/DOTNET  (12889): GarbageCollection: ❌ There is memory leaks after checking BottomSheet. See https://github.com/DIPSAS/DIPS.Mobile.UI/wiki/Performance#tips-and-tricks for help resolving the leaks.

Hot-path for BottomSheet after the sheet is closed

DIPS.Mobile.UI.Components.BottomSheets.BottomSheet
	DIPS.Mobile.UI.Components.BottomSheets.Header.BottomSheetHeader
		Action
			Microsoft.Maui.Controls.Command.[]c__DisplayClass4_0
				Action<Object>
					Microsoft.Maui.Controls.Command
						Microsoft.Maui.Controls.WeakCommandSubscription.CommandCanExecuteSubscription
							Microsoft.Maui.Controls.WeakCommandSubscription
								DIPS.Mobile.UI.Components.Buttons.Button
									Action<Object,EventArgs>

See attached archive with gcdump files for base line and memory state after leak.
bottomsheet-gcdump.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions