Unowned self
The closure which determines the tutorial’s description captures a strong reference of self and creates a reference cycle. Since the closure doesn’t exist after you release the tutorial object from memory, self will never be nil so you can change the strong reference to an unowned one using a capture list:
lazy var tutorialDescription: () -> String = { [unowned self] in
return "(self.title) (self.category)"
}
This breaks the reference cycle. All the deinit methods work as before and output the following to the console:
Goodbye Cosmin!
Goodbye Memory management! Goodbye Ray!
There’s one more case which may lead to reference cycles: working with asynchronous closures.