[swift-evolution] What about garbage collection?

Joe Groff jgroff at apple.com
Mon Feb 8 14:42:24 CST 2016

> On Feb 8, 2016, at 12:39 PM, FĂ©lix Cloutier <felixcca at yahoo.ca> wrote:
> I should check because it's been a while, but in Objective-C loops that quickly modified references, I've measured objc_retain make up to 15% of the loop's cost. My understanding is that most of that cost comes from tracking references in a global hash map, which I can't imagine being particularly kind to memory use or cache performance either.

That's less of a problem in modern Objective-C and Swift. On ARM64 and 64-bit Mac targeting >=10.11, the refcount for ObjC objects is encoded in the 'isa' word. Swift objects always store the refcount inline in the object as well. (In the worst case, consulting a hash map is definitely not ideal, but is going to be less thrashy than scanning the entire heap.)


More information about the swift-evolution mailing list