diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2016-10-12 04:46:18 -0600 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-10-12 11:46:18 +0100 |
commit | 50ac8e06da7ca2fc44dc33a4dbc96d24a597f037 (patch) | |
tree | 079a5f33597c993a5c168adcd9d1dc1fc4fa8a40 /Xamarin.Forms.Platform.iOS/Renderers | |
parent | 0a9f7bbc5598906feb59bae714d5bbc6d37919e2 (diff) | |
download | xamarin-forms-50ac8e06da7ca2fc44dc33a4dbc96d24a597f037.tar.gz xamarin-forms-50ac8e06da7ca2fc44dc33a4dbc96d24a597f037.tar.bz2 xamarin-forms-50ac8e06da7ca2fc44dc33a4dbc96d24a597f037.zip |
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/Renderers')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs | 8 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/TabletMasterDetailRenderer.cs | 79 |
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 654fc8ed..fdbd116d 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 7b54faf6..a3fbd2ab 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; } |