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

Retain cycles #2

Open
DaleLJefferson opened this issue Jul 7, 2014 · 3 comments
Open

Retain cycles #2

DaleLJefferson opened this issue Jul 7, 2014 · 3 comments

Comments

@DaleLJefferson
Copy link

Everything in the VIPER TODO example is using strong references.

  • View controllers is strongly referenced by the Wireframes.
  • Presenters are strongly referenced by the View controllers.
  • View controllers are strongly referenced by the Presenters.
  • And so on.

Unless i'm missing something this will result in nothing being released from memory. Is this behaviour intended?

I we are allocating all the dependancies, wireframes, presenters, etc in the app delegate how does this scale to a large application. Is there room in this architecture for lazy initialisation?

@jeffgilbert
Copy link

You are correct. This was a simple oversight. I haven't though of a way to make this foolproof.

In general, you should the following references.
strong: View -> Presenter -> Interactor
weak: Interactor -> Presenter -> View

We know that the iOS view controller mechanism will keep the view controller properly referenced. From the point of view of the view controller (i.e. View), the Presenter is just an implementation detail. In that regard, the View is the parent and the Presenter is the child. Following standard parent–child relationships, the parent should strongly reference the child and the child should weakly reference the parent.

Similarly, the Interactor is just an implementation detail of the Presenter, so the Presenter is the parent and the Interactor is the child.

@jeffgilbert
Copy link

The Wireframe is responsible for wiring up all of the components for a screen, e.g. View, Presenter and Interactor. This is usually done in a lazy fashion; at the time a screen is requested.

@AaronZhang2015
Copy link

Will you update the demo code to fix the question?

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

No branches or pull requests

3 participants