summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-10-12 10:46:18 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-10-12 19:47:52 (GMT)
commit25254097b80ef9bb7ebf5d119d2326dcccbedd88 (patch)
treed28585718cfe3db028830a8dac5264ee52fd12e1
parentb39cd18d627e1a69e52aa2a099029f30db4823ec (diff)
downloadxamarin-forms-25254097b80ef9bb7ebf5d119d2326dcccbedd88.zip
xamarin-forms-25254097b80ef9bb7ebf5d119d2326dcccbedd88.tar.gz
xamarin-forms-25254097b80ef9bb7ebf5d119d2326dcccbedd88.tar.bz2
Fix MasterDetailPage/NavigationPage leaks on iPad (#426)
* Remove Master page property changed handler to eliminate leak * Fix memory leaks with MasterDetailPage and NavigationPage on iOS
-rw-r--r--Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44166.cs10
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs8
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs79
3 files changed, 57 insertions, 40 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44166.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44166.cs
index 4006faa..40264f0 100644
--- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44166.cs
+++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla44166.cs
@@ -61,7 +61,7 @@ namespace Xamarin.Forms.Controls
};
}
- #if UITEST
+#if UITEST
[Test]
public void Bugzilla44166Test()
{
@@ -71,7 +71,7 @@ namespace Xamarin.Forms.Controls
RunningApp.WaitForElement(q => q.Marked("Back"));
RunningApp.Tap(q => q.Marked("Back"));
- for(int n = 0; n < 10; n++)
+ for (var n = 0; n < 10; n++)
{
RunningApp.WaitForElement(q => q.Marked("GC"));
RunningApp.Tap(q => q.Marked("GC"));
@@ -82,7 +82,7 @@ namespace Xamarin.Forms.Controls
}
}
- var pageStats = string.Empty;
+ string pageStats = string.Empty;
if (_44166MDP.Counter > 0)
{
@@ -106,7 +106,7 @@ namespace Xamarin.Forms.Controls
Assert.Fail($"At least one of the pages was not collected: {pageStats}");
}
- #endif
+#endif
}
[Preserve(AllMembers = true)]
@@ -121,7 +121,7 @@ namespace Xamarin.Forms.Controls
Master = new _44166Master();
Detail = new _44166Detail();
- }
+ }
~_44166MDP()
{
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
index 654fc8e..fdbd116 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs
@@ -831,7 +831,13 @@ namespace Xamarin.Forms.Platform.iOS
if (disposing)
{
((IPageController)Child).SendDisappearing();
- Child = null;
+
+ if (Child != null)
+ {
+ Child.PropertyChanged -= HandleChildPropertyChanged;
+ Child = null;
+ }
+
_tracker.Target = null;
_tracker.CollectionChanged -= TrackerOnCollectionChanged;
_tracker = null;
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
index 7b54faf..a3fbd2a 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs
@@ -57,10 +57,7 @@ namespace Xamarin.Forms.Platform.iOS
IPageController PageController => Element as IPageController;
IElementController ElementController => Element as IElementController;
- protected MasterDetailPage MasterDetailPage
- {
- get { return _masterDetailPage ?? (_masterDetailPage = (MasterDetailPage)Element); }
- }
+ protected MasterDetailPage MasterDetailPage => _masterDetailPage ?? (_masterDetailPage = (MasterDetailPage)Element);
IMasterDetailPageController MasterDetailPageController => MasterDetailPage as IMasterDetailPageController;
@@ -71,36 +68,50 @@ namespace Xamarin.Forms.Platform.iOS
protected override void Dispose(bool disposing)
{
- if (!_disposed && disposing)
- {
- if (Element != null)
- {
- PageController.SendDisappearing();
- Element.PropertyChanged -= HandlePropertyChanged;
- Element = null;
- }
-
- if (_tracker != null)
- {
- _tracker.Dispose();
- _tracker = null;
- }
-
- if (_events != null)
- {
- _events.Dispose();
- _events = null;
- }
-
- if (_masterController != null)
- {
- _masterController.WillAppear -= MasterControllerWillAppear;
- _masterController.WillDisappear -= MasterControllerWillDisappear;
- }
-
- _disposed = true;
- }
- base.Dispose(disposing);
+ if (_disposed)
+ {
+ return;
+ }
+
+ _disposed = true;
+
+ if (disposing)
+ {
+ if (Element != null)
+ {
+ PageController.SendDisappearing();
+ Element.PropertyChanged -= HandlePropertyChanged;
+
+ if (MasterDetailPage?.Master != null)
+ {
+ MasterDetailPage.Master.PropertyChanged -= HandleMasterPropertyChanged;
+ }
+
+ Element = null;
+ }
+
+ if (_tracker != null)
+ {
+ _tracker.Dispose();
+ _tracker = null;
+ }
+
+ if (_events != null)
+ {
+ _events.Dispose();
+ _events = null;
+ }
+
+ if (_masterController != null)
+ {
+ _masterController.WillAppear -= MasterControllerWillAppear;
+ _masterController.WillDisappear -= MasterControllerWillDisappear;
+ }
+
+ ClearControllers();
+ }
+
+ base.Dispose(disposing);
}
public VisualElement Element { get; private set; }