HiveBrain v1.2.0
Get Started
← Back to all entries
principleModerate

Is reference counting GC vs. tracing GC a language property or an implementation property?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
referencecountinglanguagepropertyimplementationtracing

Problem

We sometimes hear "Swift doesn't do classic (tracing) GC, it uses ARC."

But I'm not sure if there is anything in the Swift semantics that requires reference counting. It seems that one could build one's own Swift compiler and runtime to use tracing GC.

So what exactly is "reference-counted" about Swift? Apple's implementation or the language itself? Are there parts of the language or the library that so strongly support ARC that we can use that label for the language itself?

Solution

Swift guarantees that once the last reference to an object is dropped the object is deinitialized, and the deinit code is immediately run.

Obtaining this kind of guarantee through GC is not possible - at least, not without sacrifying performance. Standard GC mechanisms only ensure the deinit code is eventually run, e.g. at the next GC cycle. For precise semantics, you need a reference count somewhere.

Context

StackExchange Computer Science Q#50981, answer score: 10

Revisions (0)

No revisions yet.