dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
21.98k stars 1.72k forks source link

CarouselView leaks memory when having 5 items or more #23825

Open fmoDev opened 1 month ago

fmoDev commented 1 month ago

Description

Having a simple ContentPage with a CarouselView bound to some items like the following, leaks memory on Android when viewing more than 5 items:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="SomeNamespace.LeakingPage">
    <CarouselView ItemsSource="{Binding Items}" IsBounceEnabled="True" Loop="False">
        <CarouselView.ItemTemplate>
            <DataTemplate>
                <Label Text="{Binding SomeProperty}" />
            </DataTemplate>
        </CarouselView.ItemTemplate>
    </CarouselView>
</ContentPage>

Also, setting Loop to true and IsBounceEnabled to false leaks memory with just 1 item in the list and swiping a least 3 times

Steps to Reproduce

1-Use the MAUI sample controls gallery: https://github.com/dotnet/maui-samples/tree/main/8.0/UserInterface/ControlGallery

2- Use and setup https://github.com/AdamEssenmacher/MemoryToolkit.Maui for memory leak detection. Detection can be set for all pages using the MainPage constructor:

public MainPage()
{
    InitializeComponent();

    NavigateCommand = new Command<Type>(
        async (Type pageType) =>
        {
            Page page = (Page)Activator.CreateInstance(pageType);
            LeakMonitorBehavior.SetCascade(page, true);
            await Navigation.PushAsync(page);
        });

    BindingContext = this;
}

3- Navigate to CarouselViewDemoPage, swipe through 5 photos at least then go back

Link to public reproduction project repository

No response

Version with bug

8.0.70 SR7

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

I was not able test on other platforms

Affected platform versions

Android 8.1, 13, 14

Did you find any workaround?

No response

Relevant log output

No response

github-actions[bot] commented 1 month ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

Zhanglirong-Winnie commented 1 month ago

This issue has been verified using Visual Studio 17.11.0 Preview 5.0(8.0.70). Can repro on Android platform.

Stxtics commented 1 month ago

I'm also experiencing this issue which has been spotted pretty close to having a release candidate ready for MAUI after migrating from Xamarin.

jamboharris commented 1 week ago

I've seen the same issue. It's causing a major issue for us in our Maui migration, because the app crashes regularly due to the amount of memory being used. Is there any update on this? It seems quite a significant problem!