Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?
like image 397
Banannzza Avatar asked Jan 25 '26 20:01

Banannzza


1 Answers

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
like image 192
Banannzza Avatar answered Jan 29 '26 07:01

Banannzza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!