Browse Source

Merge pull request #10173 from DmitryZhelnin/10151-fix-transitions-memory-leak

Fix transitions memory leak
pull/10411/head
Max Katz 4 years ago
committed by GitHub
parent
commit
ec7fc6a303
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      src/Avalonia.Base/Animation/Animatable.cs

14
src/Avalonia.Base/Animation/Animatable.cs

@ -27,6 +27,7 @@ namespace Avalonia.Animation
AvaloniaProperty.Register<Animatable, Transitions?>(nameof(Transitions)); AvaloniaProperty.Register<Animatable, Transitions?>(nameof(Transitions));
private bool _transitionsEnabled = true; private bool _transitionsEnabled = true;
private bool _isSubscribedToTransitionsCollection = false;
private Dictionary<ITransition, TransitionState>? _transitionState; private Dictionary<ITransition, TransitionState>? _transitionState;
/// <summary> /// <summary>
@ -62,6 +63,11 @@ namespace Avalonia.Animation
if (Transitions is object) if (Transitions is object)
{ {
if (!_isSubscribedToTransitionsCollection)
{
_isSubscribedToTransitionsCollection = true;
Transitions.CollectionChanged += TransitionsCollectionChanged;
}
AddTransitions(Transitions); AddTransitions(Transitions);
} }
} }
@ -72,7 +78,7 @@ namespace Avalonia.Animation
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This method should not be called from user code, it will be called automatically by the framework /// This method should not be called from user code, it will be called automatically by the framework
/// when a control is added to the visual tree. /// when a control is removed from the visual tree.
/// </remarks> /// </remarks>
protected void DisableTransitions() protected void DisableTransitions()
{ {
@ -82,6 +88,11 @@ namespace Avalonia.Animation
if (Transitions is object) if (Transitions is object)
{ {
if (_isSubscribedToTransitionsCollection)
{
_isSubscribedToTransitionsCollection = false;
Transitions.CollectionChanged -= TransitionsCollectionChanged;
}
RemoveTransitions(Transitions); RemoveTransitions(Transitions);
} }
} }
@ -110,6 +121,7 @@ namespace Avalonia.Animation
} }
newTransitions.CollectionChanged += TransitionsCollectionChanged; newTransitions.CollectionChanged += TransitionsCollectionChanged;
_isSubscribedToTransitionsCollection = true;
AddTransitions(toAdd); AddTransitions(toAdd);
} }

Loading…
Cancel
Save