/Blog_Reference_Cycle_Delegate_Closures

Solve memory management in delegate, closures through weak var and [self weak]

Primary LanguageSwift

(Lost Ship)

Problem

When I encountered closures and delegate for the first time, I’ve noticed people put [weak self] in closures and weak var in front a delegate property. I’ve wondered why.

Prerequisite

This isn’t a tutorial for beginners. The following list is what I expect from my readers to know.

  1. How to pass data between view controllers with Delegate
  2. Memory management in Swift with ARC.
  3. Closures capture list
  4. Protocols as Type

Don’t worry if you aren’t confident with the materials above. I’ve covered all of them in my previous articles and YouTube tutorials. You may find the required knowledge and my productive development tools in a single basket here.


You may read the full tutorial here