For the More Curious: Can I Retrieve the Reference Count of an Instance?

Unfortunately, Swift does not give you access to the actual reference count of any instances.

Even if you could ask an instance what its reference count is, the answer you get might not be what you expect. Throughout this chapter, we said things like, “At this point, the reference count is 2.” That was a white lie.

Conceptually, it is perfectly reasonable for you to think of reference counts the way we described. Under the hood, the compiler is free to insert additional calls to retain (increment the reference count) and release (decrement the reference count). As long as it does its job correctly, there is no harm to your program. If you could ask what the actual ...

Get Swift Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.