Settings

Theme

Bits and Side Tables: How Reference Counting Works Internally in Swift

blog.jacobstechtavern.com

2 points by jakey_bakey 3 months ago · 1 comment

Reader

Someone 3 months ago

> When the strong refCount went to zero but there were weak references remaining, the object was deinitialised but not deallocated: it stuck around in a “zombie” state.

[…]

> Surprise, surprise, unowned references are basically implemented the same way as pre-Swift-4 weak references.

I see a possible improvement there: instead of not freeing the memory of an object, tell the memory allocator “you can take back all of this allocation, except for the first headersize bytes” (a realloc to a smaller size that guarantees to not move the object).

That would require extending the API of the memory allocator, and thus, make it impossible to swap in a different C(++)-style allocator, but would decrease the size of those zombie object remnants that hang around (probably to 16 bytes, on 64-bit systems)

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection