summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2016-10-12 10:46:18 (GMT)
committerRui Marinho <me@ruimarinho.net>2016-10-12 10:46:18 (GMT)
commit50ac8e06da7ca2fc44dc33a4dbc96d24a597f037 (patch)
tree079a5f33597c993a5c168adcd9d1dc1fc4fa8a40 /Xamarin.Forms.Platform.iOS
parent0a9f7bbc5598906feb59bae714d5bbc6d37919e2 (diff)
downloadxamarin-forms-50ac8e06da7ca2fc44dc33a4dbc96d24a597f037.zip
xamarin-forms-50ac8e06da7ca2fc44dc33a4dbc96d24a597f037.tar.gz
xamarin-forms-50ac8e06da7ca2fc44dc33a4dbc96d24a597f037.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
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs8
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs79
2 files changed, 52 insertions, 35 deletions
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; }