Skip to content

Conversation

kkwpsv
Copy link
Contributor

@kkwpsv kkwpsv commented Jun 3, 2025

What does the pull request do?

Fix infinite animation memory leak.

What is the current behavior?

Memory leak, even after the window is closed.
Here's a example code to reproduce.

<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"
        xmlns:local="using:AvaloniaTestApp"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaTestApp.MainWindow"
        Title="AvaloniaTestApp">
  <Window.Styles>
    <Style Selector="Button">
      <Style.Animations>
        <Animation FillMode="None"
                   IterationCount="Infinite"
                   PlaybackDirection="Normal"
                   Duration="0:0:1.5">
          <KeyFrame Cue="0%">
            <Setter Property="Opacity" Value="0.2" />
          </KeyFrame>
          <KeyFrame Cue="20%">
            <Setter Property="Opacity" Value="0.1" />
          </KeyFrame>
          <KeyFrame Cue="50%">
            <Setter Property="Opacity" Value="0.05" />
          </KeyFrame>
          <KeyFrame Cue="80%">
            <Setter Property="Opacity" Value="0.1" />
          </KeyFrame>
          <KeyFrame Cue="100%">
            <Setter Property="Opacity" Value="0.2" />
          </KeyFrame>
        </Animation>

      </Style.Animations>
    </Style>
  </Window.Styles>
  <Button Background="Red" Width="100" Height="100"/>
</Window>

Here's the key retention paths from dotMemory.
dotMemory

What is the updated/expected behavior with this PR?

No memory leak.

How was the solution implemented (if it's not obvious)?

Dispose when StyleInstance dispose.

Checklist

Breaking changes

None.

Obsoletions / Deprecations

Fixed issues

None.

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 12.0.999-cibuild0056841-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@jmacato jmacato added this pull request to the merge queue Jun 3, 2025
@jmacato jmacato added the bug label Jun 3, 2025
Merged via the queue into AvaloniaUI:master with commit ae37ccd Jun 3, 2025
11 checks passed
@MrJul MrJul added the backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch label Jun 3, 2025
MrJul pushed a commit that referenced this pull request Jun 5, 2025
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants