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

Commit 9f73e70

Browse files
authored
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.
1 parent 6c98fa2 commit 9f73e70

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/private/MDMViewControllerTransitionController.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ @implementation MDMViewControllerTransitionController {
2727
// a weak reference to the view controller here.
2828
__weak UIViewController *_associatedViewController;
2929

30-
UIPresentationController *_presentationController;
30+
__weak UIPresentationController *_presentationController;
3131

3232
MDMViewControllerTransitionContext *_context;
3333
__weak UIViewController *_source;
@@ -93,10 +93,14 @@ - (UIPresentationController *)presentationControllerForPresentedViewController:(
9393
return nil;
9494
}
9595
id<MDMTransitionWithPresentation> withPresentation = (id<MDMTransitionWithPresentation>)_transition;
96-
_presentationController = [withPresentation presentationControllerForPresentedViewController:presented
97-
presentingViewController:presenting
98-
sourceViewController:source];
99-
return _presentationController;
96+
UIPresentationController *presentationController =
97+
[withPresentation presentationControllerForPresentedViewController:presented
98+
presentingViewController:presenting
99+
sourceViewController:source];
100+
// _presentationController is weakly-held, so we have to do this local var dance to keep it
101+
// from being nil'd on assignment.
102+
_presentationController = presentationController;
103+
return presentationController;
100104
}
101105

102106
#pragma mark - MDMViewControllerTransitionContextDelegate

0 commit comments

Comments
 (0)