[iOS] Fix NavigationPage memory leak when back button title is set (#523)

* fix memory leak

* fix parent

* added comment
This commit is contained in:
adrianknight89 2017-02-09 10:03:41 -06:00 коммит произвёл Rui Marinho
Родитель faa6eae8e7
Коммит 56e3629c82
3 изменённых файлов: 64 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,61 @@
using System;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 44047, "Memory leak when using SetBackButtonTitle on iOS", PlatformAffected.iOS)]
public class Bugzilla44047 : TestMasterDetailPage
{
protected override void Init()
{
Master = new ContentPage
{
Title = "Menu"
};
Detail = new NavigationPage(new Page1());
}
}
public class Page1 : ContentPage
{
public Page1()
{
Title = "Page1";
Content = new Button
{
Text = "Open Page2",
Command = new Command(async o =>
{
await (Parent as NavigationPage).PushAsync(new Page2());
})
};
}
}
public class Page2 : ContentPage
{
public Page2()
{
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
Title = "Page2";
System.Diagnostics.Debug.WriteLine("Constructor");
NavigationPage.SetBackButtonTitle(this, "Custom");
}
~Page2()
{
System.Diagnostics.Debug.WriteLine("Finalizer");
}
}
}

Просмотреть файл

@ -143,6 +143,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43313.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43469.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla44047.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43941.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43663.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Bugzilla43867.cs" />

Просмотреть файл

@ -366,8 +366,8 @@ namespace Xamarin.Forms.Platform.iOS
var titleText = NavigationPage.GetBackButtonTitle(page);
if (titleText != null)
{
pack.NavigationItem.BackBarButtonItem =
new UIBarButtonItem(titleText, UIBarButtonItemStyle.Plain, async (o, e) => await PopViewAsync(page));
// adding a custom event handler to UIBarButtonItem for navigating back seems to be ignored.
pack.NavigationItem.BackBarButtonItem = new UIBarButtonItem { Title = titleText, Style = UIBarButtonItemStyle.Plain };
}
var pageRenderer = Platform.GetRenderer(page);