swiftweak-referencesstrong-referencesunowned-references

Understanding weak and unowned reference in Swift under the hood


I want fully understand what going inside weak and unowned referance in Swift. For this i read MikeAsh and got some questions.

What already known:

  1. when there is no weak (and, i suppose, unowned) object reference, the strong reference counter is stored directly in the memory area of the object
  2. when a weak link appears, the second word in the object memory is reused to reference the side table
  3. side table has link to the object
  4. weak link refers to this side table

And what i want to clearify:

  1. What else side table store inside except link to the object and number of strong reference?
  2. Is unowned reference link to the side table too? If not and unowned link refers to the object memory what about performance between weak and unowned ?

Solution

  • Okay, i found out.

    1. Unowned link points to the object as well as strong.
    2. Unowned link faster than weak.
    3. Side table stores strong RC, weak RC, unowned RC, link to the object and some flags