Essential Developer

View Original

Clean iOS Architecture pt.4: Clean Memory Management in Swift with WeakRef

Watch on YouTube

We must be careful with weak properties as they can sometimes damage the design of our systems, especially when crossing module boundaries. In this video, we’d like to share with you a way to avoid retain cycles by using a WeakRef type, so there's no need to make your class properties weak.

WeakRef is a type-safe alternative to weak properties that maintains a clean cross-boundary separation of concerns. By using a WeakRef, we can leave the composition (and memory management) responsibility to the Main (or Factory/Composer) module.

You can find the source code on GitHub.

For more, visit the Clean iOS Architecture Playlist.

Subscribe now to our Youtube channel and catch free new episodes every week.