Skip to content

Commit

Permalink
Memory leak on TintedImageBehavior fix (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marioo1357 authored Feb 14, 2024
1 parent de4eecc commit cc62c6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected override void OnAttachedTo(View bindable, AView platformView)
{
ApplyTintColor(bindable, platformView);

bindable.PropertyChanged += OnElementPropertyChanged;
this.PropertyChanged += (s, e) =>
{
if (e.PropertyName == TintColorProperty.PropertyName)
Expand All @@ -26,13 +27,15 @@ protected override void OnAttachedTo(View bindable, AView platformView)
}

/// <inheritdoc/>
protected override void OnDetachedFrom(View bindable, AView platformView) =>
protected override void OnDetachedFrom(View bindable, AView platformView)
{
ClearTintColor(bindable, platformView);
bindable.PropertyChanged -= OnElementPropertyChanged;
}

void ApplyTintColor(View element, AView control)
{
var color = TintColor;
element.PropertyChanged += OnElementPropertyChanged;

switch (control)
{
Expand Down Expand Up @@ -98,7 +101,6 @@ void OnElementPropertyChanged(object? sender, PropertyChangedEventArgs args)

void ClearTintColor(View element, AView control)
{
element.PropertyChanged -= OnElementPropertyChanged;
switch (control)
{
case ImageView image:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ void OnElementPropertyChanged(object? sender, PropertyChangedEventArgs e)
}

/// <inheritdoc/>
protected override void OnDetachedFrom(View bindable, UIView platformView) =>
protected override void OnDetachedFrom(View bindable, UIView platformView)
{
bindable.PropertyChanged -= OnElementPropertyChanged;
ClearTintColor(platformView, bindable);
}

void ClearTintColor(UIView platformView, View element)
{
element.PropertyChanged -= OnElementPropertyChanged;
switch (platformView)
{
case UIImageView imageView:
Expand Down

0 comments on commit cc62c6f

Please sign in to comment.