mutualmobile / VIPER-TODO

Example project architected using VIPER
MIT License
70 stars 15 forks source link

Retain cycles #2

Open DaleLJefferson opened 10 years ago

DaleLJefferson commented 10 years ago

Everything in the VIPER TODO example is using strong references.

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 commented 10 years ago

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 commented 10 years ago

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 commented 9 years ago

Will you update the demo code to fix the question?