Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak on infinite animation #17192

Open
kikipoulet opened this issue Oct 4, 2024 · 0 comments
Open

Memory leak on infinite animation #17192

kikipoulet opened this issue Oct 4, 2024 · 0 comments
Labels

Comments

@kikipoulet
Copy link

Describe the bug

For reference, found when working with SukiUI library : kikipoulet/SukiUI#245

memoryleak

Basically, it seems that memory from infinite animation aren't correctly cleaned.

Generating 100 "animated" buttons every second :

{246B9F3E-C3AA-48C7-A2BE-5C0CF7754ECC}

Generating the same buttons, without the infinite animation :

{1C4D6C7E-2154-4A8B-8D29-F716E2DF3456}

To Reproduce

axaml

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaApplication5.MainWindow"
        Title="AvaloniaApplication5">
    <Window.Styles>
        <Style Selector="Button">
            <Style.Animations>
                <Animation FillMode="None"
                           IterationCount="Infinite"
                           PlaybackDirection="Normal"
                           Duration="0:0:1.5">
                    <Animation.Easing>
                        <QuadraticEaseInOut />
                    </Animation.Easing>
                    <KeyFrame Cue="0%">
                        <Setter Property="RotateTransform.Angle" Value="0" />
                    </KeyFrame>
                    <KeyFrame Cue="30%">
                        <Setter Property="RotateTransform.Angle" Value="0" />
                    </KeyFrame>

                    <KeyFrame Cue="100%">
                        <Setter Property="RotateTransform.Angle" Value="360" />
                    </KeyFrame>
                </Animation> 

            </Style.Animations>
        </Style>
    </Window.Styles>
    <StackPanel>
        <Button Content="test" Click="Button_OnClick"></Button>
        <StackPanel Name="SP"></StackPanel>
    </StackPanel>
</Window>

C#

using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Threading;

namespace AvaloniaApplication5;

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
    
      private void Button_OnClick(object? sender, RoutedEventArgs e)
        {
            var stackpanel = this.Get<StackPanel>("SP");
    
            Task.Run(() =>
            {
                while (true)
                {
                    Dispatcher.UIThread.Invoke(() =>
                    {
                        stackpanel.Children.Clear();


                        for (int i = 0; i < 100; i++)
                        {
                            stackpanel.Children.Add(new Button() { Content = "test" });
                        }
                    });

                    Thread.Sleep(1000);
                }
            });
        }
}

{842EC8CB-EE6C-42DA-BA11-5A674BAFE64B}

Expected behavior

No response

Avalonia version

11.2.0-rc1

OS

Windows

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant