Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customBarViewController is nil after dismissPopupBar but still retained by LNPopupBar #232

Closed
antiraum opened this issue Feb 21, 2018 · 9 comments
Labels

Comments

@antiraum
Copy link

I'm setting a customBarViewController like this:

let popupBarVC = PopupBarViewController()
let contentVC = PopupContentViewController()

popupBar.customBarViewController = popupBarVC

presentPopupBar(withContentViewController: contentVC, openPopup: true, animated: true, completion: nil)

when I'm dismissing the popupBar the customBarViewController property becomes nil

// popupBar.customBarViewController is still set here

dismissPopupBar(animated: true) {
    // self.popupBar.customBarViewController is nil here
}

However the PopupBarViewController instance is not deallocated and according to Xcode's Memory Graph Debugger it is still retained by an instance of LNPopupBar.

If I repeat to present and dismiss the popupBar like this I accumulate instances of PopupBarViewController that are all retained by different instances of LNPopupBar.

screen shot 2018-02-21 at 10 35 32
screen shot 2018-02-21 at 10 36 04

If I keep a reference to the PopupBarViewController instance myself and reuse that to set it to the popupBar.customBarViewController property everytime I'm going to present the popupBar, the PopupBarViewController instance will be retained by many LNPopupBar instances.

Seems to me that LNPopupBar instances are not released when they should be (after dismissPopupBar).

I'm using
LNPopupController v2.5.10
Xcode 9.2

@LeoNatan
Copy link
Owner

Thank you for the great report!
I will look into this ASAP.

@LeoNatan
Copy link
Owner

Considering how the system works, the popup bar itself is created on demand and only released when the presenting controller is released. This is to allow, for example, customization done by the user to persist between presentations.

I do however see a problem where cleanup should be performed after dismissing the popup.

@antiraum
Copy link
Author

antiraum commented Feb 21, 2018

It would be fine for me if the popup bar is not released until the presenting view controller is released. But it seems a new popup bar instance is created on every present.

@LeoNatan
Copy link
Owner

LeoNatan commented Feb 21, 2018

Only one bar should be created per presenting controller.

@LeoNatan
Copy link
Owner

Yes, I see what you mean. Investigating

@LeoNatan
Copy link
Owner

LeoNatan commented Feb 21, 2018

//No longer need to retain the popup controller after dismissing.
objc_setAssociatedObject(self, _LNPopupControllerKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

Well that about will do it 😆

@LeoNatan
Copy link
Owner

OK, found a leak that caused previous bars to remain in memory.

But I still think the correct behavior of the system should be to only release the bar upon the presentation controller release.

@LeoNatan
Copy link
Owner

Please try now with 2.5.11.

Thanks

@antiraum
Copy link
Author

fix confirmed. thanks!

@LeoNatan LeoNatan added the bug label Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants