xamarin / XamarinCommunityToolkit

The Xamarin Community Toolkit is a collection of Animations, Behaviors, Converters, and Effects for mobile development with Xamarin.Forms. It simplifies and demonstrates common developer tasks building iOS, Android, and UWP apps with Xamarin.Forms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] [MauiCompat] ByteArrayToImageSourceConverter Memory runaway

Skyhikeeper opened this issue · comments

Description

When using the toolkit to display an image on a view the resource is never discarded so the amount of memory usage grows all the time.

Stack Trace

CommunityToolkit.Maui.Converters.ByteArrayToImageSourceConverter+<>c__DisplayClass8_0 38635 6358971072 6358971072

Link to Reproduction Sample

Steps to Reproduce

  1. add the toolkit to the xaml view

<ContentPage.Resources>
    <ResourceDictionary>
        <toolkit:ByteArrayToImageSourceConverter x:Key="ByteArrayToImageSourceConverter" />
    </ResourceDictionary>
</ContentPage.Resources>

<Grid RowDefinitions = "0.75*,150,0.1*" 
      ColumnDefinitions =" *,*,*,*,*"
      Margin="5,0,5,0">
    <Image Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="5" 
        MinimumHeightRequest="50" 
        Margin="5"
        Source="{Binding BigPic,Mode=OneWay, Converter={StaticResource ByteArrayToImageSourceConverter}}" 
        Aspect="AspectFit">
    </Image>
    <Image Grid.Row="1" Grid.Column="0" 
           Margin="5,0,5,0" 
           MaximumHeightRequest="150" 
           Aspect="AspectFit" 
           Source="{Binding Pic1,Mode=OneWay, Converter={StaticResource ByteArrayToImageSourceConverter}}" 
           HorizontalOptions="Center" >
    </Image>
    <Image Grid.Row="1" Grid.Column="1" 
           Margin="5,0,5,0" 
           MaximumHeightRequest="150" 
           Aspect="AspectFit" 
           Source="{Binding Pic2,Mode=OneWay, Converter={StaticResource ByteArrayToImageSourceConverter}}" 
           HorizontalOptions="Center">
    </Image>
    <Image Grid.Row="1" Grid.Column="2" 
           Margin="5,0,5,0" 
           MaximumHeightRequest="150" 
           Aspect="AspectFit" 
           Source="{Binding Pic3,Mode=OneWay, Converter={StaticResource ByteArrayToImageSourceConverter}}" 
           HorizontalOptions="Center">
    </Image>
    <Image Grid.Row="1" Grid.Column="3" 
           Margin="5,0,5,0" 
           MaximumHeightRequest="150" 
           Aspect="AspectFit" 
           Source="{Binding Pic4,Mode=OneWay, Converter={StaticResource ByteArrayToImageSourceConverter}}"  
           HorizontalOptions="Center">
    </Image>
    <Image Grid.Row="1" Grid.Column="4" 
           Margin="5,0,5,0" 
           MaximumHeightRequest="150" 
           Aspect="AspectFit" 
           Source="{Binding Pic5,Mode=OneWay, Converter={StaticResource ByteArrayToImageSourceConverter}}" 
           HorizontalOptions="Center">
    </Image>
    <HorizontalStackLayout Grid.Row="3" Grid.ColumnSpan="5" HorizontalOptions="Center" >
        <Button
            Margin="0,0,50,0"
        Text="Reconnect"
        SemanticProperties.Hint="Reconnect to the control room"
        Command="{Binding ReconnectClickedCommand}"
        MaximumHeightRequest="50"/>
        <Button
        Text="{Binding ModelPauseStatus}"
        SemanticProperties.Hint="Pause the Image roataion"
        Command="{Binding PauseClickedCommand}"
        MaximumHeightRequest="50"/>
    </HorizontalStackLayout>
</Grid>
  1. process images to display on the view using the MVVM toolkit

  2. run application and the memory usage just increase

Expected Behavior

after each display of the image, I expect the memory usage to reduce.

Actual Behavior

after each display of the image, the memory continues to increase.

Basic Information

  • Version with issue:
  • Last known good version: Unknown
  • IDE: Visual Studio 2022 version 17.7.1
  • Platform Target Frameworks: .net7
    • iOS: na
    • Android: na
    • Windows: Windows 11
  • Android Support Library Version:
  • Nuget Packages: CommunityToolkit.Maui
  • Affected Devices: all
  • MAUI Version:

Workaround

none found

Reproduction imagery

Screenshot 2023-08-16 070208