Sidemenu: ViewControllers push same instance issue

Created on 16 Aug 2017  路  9Comments  路  Source: jonkykong/SideMenu

New Issue Checklist


I have read the guidelines for contributing and I understand:

  • [x] My issue is happening in the latest version of SideMenu.
  • [x] My issue was not solved in the README.
  • [x] My issue can not be answered on stackoverflow.com.
  • [x] My issue is not a request for new functionality that I am unwilling to build and contribute with a pull request.
  • [ ] My issue is reproducible in the demo project.

Issue Description

Hello. Thanks for great SideMenu implementation!
I instantiate SideMenu from AppDelegate and MenuViewController (UIViewController subclass) as a root. In MenuViewController I call push... func and pass ViewController_1() to it. But when I switch another viewController, first one does not deinit, and when I switch back it creates another instance of ViewController_1(). Sow I suppose it is a memory leak isn't it?
And I decide to create and hold viewControllers instances in MenuViewController and push same instance when need, and I can't do this because of "Pushing the same view controller instance more than once is not supported". How can I use one Instance of ViewController per menu type? Thanks!

Most helpful comment

@jonkykong Please, tell me how to do this?

Set the menu to nil when you're done with it.
Or reset it back to a new instance.

All 9 comments

This is by design.

As a singleton, it retains a reference to the menu you assign to the menu so you can easily call the menu programmatically from any screen.

To enable storyboard simplicity, there is no way to tell interface builder to use the existing instance, so instead if it recreates a VC for the menu and that takes over for any existing menu previously held.

From a design standpoint, you should restore your menu back to the desired state every time it appears, not every time it is initialized.

Ok, retain reference is not bad, but not to release it is not good for memory, because you not reuse holded viewController and forces to create new. Is it possible to push the same instance of VC several times?

Oh, you sad it retains Menu - it's OK. I'm telling about menu elemets (as ViewControllers)

I'm not familiar with your design, but of course it's possible. Either use a new instance or release the old one before pushing it again. There's plenty on StackOverflow about that.

Is it an explicit way how to release old one instance?

Set the menu to nil when you're done with it.

Or reset it back to a new instance.

@jonkykong Please, tell me how to do this?

Set the menu to nil when you're done with it.
Or reset it back to a new instance.

@jonkykong sorry to revive an old thread but how would you go about doing this if you setup sidemenu with a storyboard?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CaliCastle picture CaliCastle  路  3Comments

harshvishu picture harshvishu  路  3Comments

BhavinBhadani picture BhavinBhadani  路  5Comments

vkolosovsky picture vkolosovsky  路  4Comments

taylorhredding picture taylorhredding  路  3Comments