Daily iOS
Memory and ARC

How weak works at runtime

Why is it true that "weak is slower than strong"? Explain it with the Swift runtime's reference count layout: the inline refcount and the side table.

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

The inline refcount in the object header only holds the strong and unowned counts; the first weak reference allocates a side table and moves the counts there. From then on a weak variable points at the side table instead of the object, adding one level of indirection, and even strong operations on that object get slower.

Share a question