IOS 

Swift uses Automatic Reference Counting (ARC) to track and manage your app’s memory usage. In most cases, you do not need to think about memory management yourself.
The only time using [unowned self] or [weak self] is necessary is when you would create a strong reference cycle.

if a class owns a closure, and that closure captures a strong reference to that class, then you have a strong reference cycle between the closure and the class

 

A strong reference cycle is when there is a loop of ownership where objects end up owning each other

The only way to stop above ownership, is to do the [unowned self] or [weak self]

 

Difference between unowned and weak

 

The difference between unowned and weak is that weak is declared as an Optional while unowned is not.

If self could be nil in the closure use [weak self].
If self will never be nil in the closure use [unowned self].

A nature, universe, science, music, love lover

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami