Browse Source

Fix infinite animation memory leak. (#18980)

pull/18990/head
Shaojun Li 1 year ago
committed by GitHub
parent
commit
ae37ccd53e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 11
      src/Avalonia.Base/Styling/StyleInstance.cs

11
src/Avalonia.Base/Styling/StyleInstance.cs

@ -25,6 +25,7 @@ namespace Avalonia.Styling
private bool _isActive;
private List<ISetterInstance>? _setters;
private List<IAnimation>? _animations;
private List<IDisposable>? _animationApplyDisposables;
private LightweightSubject<bool>? _animationTrigger;
public StyleInstance(
@ -69,8 +70,9 @@ namespace Avalonia.Styling
if (_animations is not null && control is Animatable animatable)
{
_animationTrigger ??= new LightweightSubject<bool>();
_animationApplyDisposables ??= new List<IDisposable>();
foreach (var animation in _animations)
animation.Apply(animatable, null, _animationTrigger);
_animationApplyDisposables.Add(animation.Apply(animatable, null, _animationTrigger));
if (_activator is null)
_animationTrigger.OnNext(true);
@ -81,6 +83,13 @@ namespace Avalonia.Styling
{
base.Dispose();
_activator?.Dispose();
if (_animationApplyDisposables != null)
{
foreach (var item in _animationApplyDisposables)
{
item.Dispose();
}
}
}
public new void MakeShared() => base.MakeShared();

Loading…
Cancel
Save