Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

[WPF] Memory leak when you pop a TabbedPage #3372

Merged
merged 3 commits into from
Aug 31, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions Xamarin.Forms.Platform.WPF/Renderers/ViewRenderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using WControl = System.Windows.Controls.Control;
Expand Down Expand Up @@ -161,19 +162,30 @@ protected void SetNativeControl(TNativeElement native)

Element.IsNativeStateConsistent = false;

Control.Loaded += (sender, e) =>
{
Element.IsNativeStateConsistent = true;
Appearing();
};
Control.Unloaded += (sender, e) => { Disappearing(); };
Control.Loaded += Control_Loaded;
Control.Unloaded += Control_Unloaded;

Control.GotFocus += OnGotFocus;
Control.LostFocus += OnLostFocus;

UpdateBackground();
UpdateAlignment();
}

private void Control_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Control_Loaded : " + this.Control.GetType());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this Debug info

Control.Loaded -= Control_Loaded;
Element.IsNativeStateConsistent = true;
Appearing();
}

private void Control_Unloaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("Control_Unloaded : " + this.Control.GetType());
Control.Unloaded -= Control_Unloaded;
Disappearing();
}

protected virtual void Appearing()
{
Expand Down Expand Up @@ -276,7 +288,7 @@ protected virtual void Dispose(bool disposing)

if (Control != null)
{
//Console.WriteLine("Dispose : " + this.Control.GetType());
Debug.WriteLine("Dispose : " + this.Control.GetType());
Control.GotFocus -= OnGotFocus;
Control.LostFocus -= OnLostFocus;
}
Expand Down