Skip to content

Commit

Permalink
Fix several memory management issues
Browse files Browse the repository at this point in the history
Closes #232
  • Loading branch information
LeoNatan committed Feb 21, 2018
1 parent 9fbb475 commit b91d04f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions LNPopupController/LNPopupController/Private/LNPopupBar.m
Expand Up @@ -1021,6 +1021,12 @@ - (void)setCustomBarViewController:(LNPopupCustomBarViewController*)customBarVie
{
if(_customBarViewController != customBarViewController)
{
if (customBarViewController.containingPopupBar)
{
//Cleanly move the custom bar view controller from the previos popup bar.
customBarViewController.containingPopupBar.customBarViewController = nil;
}

_customBarViewController.containingPopupBar = nil;
[_customBarViewController.view removeFromSuperview];
[_customBarViewController removeObserver:self forKeyPath:@"preferredContentSize"];
Expand Down
15 changes: 14 additions & 1 deletion LNPopupController/LNPopupController/Private/LNPopupController.m
Expand Up @@ -242,6 +242,8 @@ @implementation LNPopupController

NSLayoutConstraint* _popupCloseButtonTopConstraint;
NSLayoutConstraint* _popupCloseButtonHorizontalConstraint;

id<UIViewControllerPreviewing> _previewingContext;
}

- (instancetype)initWithContainerViewController:(__kindof UIViewController*)containerController
Expand Down Expand Up @@ -1073,6 +1075,17 @@ - (LNPopupContentView *)popupContentView

- (void)dealloc
{
//Cannot use self.popupBar in this method because it returns nil when the popup state is LNPopupPresentationStateHidden.

if(_previewingContext)
{
[_containerController unregisterForPreviewingWithContext:_previewingContext];
}

if(_popupBar)
{
[_popupBar removeFromSuperview];
}
[_popupContentView removeObserver:self forKeyPath:@"popupCloseButtonStyle"];
}

Expand Down Expand Up @@ -1147,7 +1160,7 @@ - (void)presentPopupBarAnimated:(BOOL)animated openPopup:(BOOL)open completion:(

if([[NSProcessInfo processInfo] operatingSystemVersion].majorVersion >= 9)
{
[_containerController registerForPreviewingWithDelegate:self sourceView:self.popupBar];
_previewingContext = [_containerController registerForPreviewingWithDelegate:self sourceView:self.popupBarStorage];
}

[self _movePopupBarAndContentToBottomBarSuperview];
Expand Down
Expand Up @@ -65,8 +65,8 @@ - (void)dismissPopupBarAnimated:(BOOL)animated completion:(void(^)(void))complet
self.popupContentViewController.popupPresentationContainerViewController = nil;
self.popupContentViewController = nil;

//No longer need to retain the popup controller after dismissing.
objc_setAssociatedObject(self, _LNPopupControllerKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
//The LNPopupController is no longer released here.
//There should be one popup controller per presenting controller per instance.

if(completionBlock)
{
Expand Down

0 comments on commit b91d04f

Please sign in to comment.