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

leaky views - adds subview to window (in init!), never removes it #52

Closed
argh opened this issue Mar 26, 2016 · 4 comments
Closed

leaky views - adds subview to window (in init!), never removes it #52

argh opened this issue Mar 26, 2016 · 4 comments

Comments

@argh
Copy link

argh commented Mar 26, 2016

If you have the menu on a secondary page that gets opened on nav, every time you visit it it adds a new child subview to window.

"menuWrapper" is private, so you can't get access to it to force cleanup.

@argh
Copy link
Author

argh commented Mar 26, 2016

Also, I don't think its a good practice to be doing any sort of view hierarchy modification in a constructor.

As a short term hack, I did this:
var leakyMenuView: UIView?
...
let window = UIApplication.sharedApplication().keyWindow!
let wv = Set(window.subviews)
self.menuView = BTNavigationDropdownMenu(navigationController: self.navigationController, title: items.first!, items: items)
let added = Set(window.subviews).subtract(wv)
leakyMenuView = added.first

and then in my viewWillDisappear...
leakyMenuView?.removeFromSuperview()

@argh argh changed the title leaky views - adds subview to window, never removes it leaky views - adds subview to window (in init!), never removes it Mar 26, 2016
@PhamBaTho
Copy link
Owner

Thanks. I will take a look

@ghost
Copy link

ghost commented May 24, 2016

How is solution shown below?

if let navController = self.navigationController {
navController.viewControllers[navController.viewControllers.count-1].view.addSubview(self.menuWrapper)
} else {
window.addSubview(self.menuWrapper)
}

@PhamBaTho
Copy link
Owner

PhamBaTho commented Jul 4, 2017

Added an attempt to fix this issue in this commit. Feel free to reopen if there is any further issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants