From 9f73e70e382ef8291f3ad85f7ccac25994f06e43 Mon Sep 17 00:00:00 2001 From: featherless Date: Thu, 24 Aug 2017 12:54:00 -0400 Subject: [PATCH] Store the presentation controller as a weak reference. (#34) This resolves a memory leak of presented view controllers caused by transitions that make use of presentation controllers. The transition controller would hold on to the presentation controller, which would hold on to a strong reference of the presented view controller. --- .../MDMViewControllerTransitionController.m | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/private/MDMViewControllerTransitionController.m b/src/private/MDMViewControllerTransitionController.m index a5b2fae..6b5efb8 100644 --- a/src/private/MDMViewControllerTransitionController.m +++ b/src/private/MDMViewControllerTransitionController.m @@ -27,7 +27,7 @@ @implementation MDMViewControllerTransitionController { // a weak reference to the view controller here. __weak UIViewController *_associatedViewController; - UIPresentationController *_presentationController; + __weak UIPresentationController *_presentationController; MDMViewControllerTransitionContext *_context; __weak UIViewController *_source; @@ -93,10 +93,14 @@ - (UIPresentationController *)presentationControllerForPresentedViewController:( return nil; } id withPresentation = (id)_transition; - _presentationController = [withPresentation presentationControllerForPresentedViewController:presented - presentingViewController:presenting - sourceViewController:source]; - return _presentationController; + UIPresentationController *presentationController = + [withPresentation presentationControllerForPresentedViewController:presented + presentingViewController:presenting + sourceViewController:source]; + // _presentationController is weakly-held, so we have to do this local var dance to keep it + // from being nil'd on assignment. + _presentationController = presentationController; + return presentationController; } #pragma mark - MDMViewControllerTransitionContextDelegate