DEV Community

Discussion on: When to use weak self and why

Collapse
 
kodelit profile image
kodelit • Edited

Nice reading. You read about things you think you know, and yet there is always something you didn't know. :)

One thing I would like to know after reading this post is the explanation why when you use unowned reference it sometimes crashes and that It's because the other difference between weak and unowned:

  • weak will not retain the reference counter of the object and the variable will be set to nil when the last strong reference to the object was removed.
  • unowned will also not retain reference counter of the object, but variable will still hold reference to an object even if it does not exist anymore, and if you do not set it to nil explicitly (like in old times of Manual Memory Management in Objective-C) it will cause crash if you try to use it.