Does String copy storage between actors?

Correct! It's thread-safe by virtue of the reference counting being synchronized already. It's just doing a single check, and doesn't also modify the ref count, so there's no TOC/TOU concerns.

By the time you're able to call isKnownUniquelyReferenced(x), you've got a strong reference to x. At that point, it can check if the reference count is >1, indicating that some other reference must exist.

Here's an enlightening thread on this matter: isKnownUniquelyReferenced thread safety

3 Likes