Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Store the presentation controller as a weak reference. (#34)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jverkoey authored Aug 24, 2017
1 parent 6c98fa2 commit 9f73e70
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/private/MDMViewControllerTransitionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,10 +93,14 @@ - (UIPresentationController *)presentationControllerForPresentedViewController:(
return nil;
}
id<MDMTransitionWithPresentation> withPresentation = (id<MDMTransitionWithPresentation>)_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
Expand Down

0 comments on commit 9f73e70

Please sign in to comment.