6 ms·
If GC means garbage collection here, Swift definitely doesn't have that.
by mnem 7y ago
If GC means garbage collection here, Swift definitely doesn't have that.
- pjmlp 7y agoSure it does, reference counting is a GC implementation algorithm from CS point of view. The Garbage Collection Handbook, chapter 5. http://gchandbook.org/ http://gchandbook.org/ Just one key CS reference for compiler writers among a few others.
- seanmcdirmid 7y agoWhen people say GC in computer science, they don’t typically mean reference counting. Reference counting is an automatic memory management scheme along side GC, not inside it. One way to think of it is that if it lacks a separate GC phase and can’t deal with cycles, it isn’t GC.
- pjmlp 7y agoNah, that is mixing GC with tracing GC, because it is too much to type/say an additional word. Lay people also use wrong terms when talking about other scientific fields, that doesn't make them right by quantity of use.
- seanmcdirmid 7y agoI don’t think McCarthy had reference counting in mind when he coined the word garbage collection. I think it’s more likely that people say garbage collection when they actually mean the more general term of automatic memory management. No one would ever mistake arena based memory management as a form of garbage collection, for example, even though it is obviously a form of automatic memory management.
- chobytes 7y agoBy that measure C++ and Rust are a GCd languages because they have smart pointers.
- otabdeveloper1 7y agoYes and no. "No GC" means "no mandatory GC when data isn't shared between threads".
- the_duke 7y agoNo because in Rust and C++ using smart pointers is an explicit choice that is applied manually when required and is present both in the type signature everywhere a reference counted type is used, and in the construction of values. In Swift the reference counting is a implementation detail of automatic and transparent memory management. (that you only really have to care about when you have cycles) That's why Swift definitely counts as a GC language for me. Sure, if you put things behind a Arc<T> or shared_ptr you use reference counting in C++ and Rust, but it is not an inherent feature of the language.
- chobytes 7y agoARC only applies to reference types. The programmer has acess to value types, and manual memory management if they want it.
- 0815test 7y agoIn Rust, using smart pointers is not much of an "explicit choice" - it's simply the idiomatic thing to do when something might be kept around by more than one parent object. Rc<T> basically means that there are multiple sources of control over T's lifetime, but these are all within a single thread; and Arc<T> signals that the control might extend to multiple threads. It's not "mere implementation" that we're dealing with here; it's the very semantics of the code as it relates to Rust's expanded take on the well-known RAII pattern. Swift simply lacks an equivalent to either the Rc<> specifier or e.g. Rust's Box<>, which expresses the semantics of an object which is heap-allocated and accessed via an indirection, and verifiably has at all times a unique "owner" controlling its lifetime (as per usual RAII).
- steveklabnik 7y agoYou can argue it’s an explicit choice because you can often choose to structure your code in a way that doesn’t require Rc. Of course, it exists because sometimes, you do have to or want to, but those cases are pretty rare in my experience.
- jasode 7y ago>, reference counting is a GC implementation algorithm from CS point of view. The Garbage Collection Handbook, chapter 5. Yes, that GC book always gets cited to educate everyone on terminology but it never resolves or finalizes how "garbage collection" is actually discussed in regular conversations. I made previous comments on why citing that book just adds to the confusion of how people typically communicated that rc != gc before that GC book was published. https://news.ycombinator.com/item?id=11764887 https://news.ycombinator.com/item?id=11764887 https://news.ycombinator.com/item?id=7866732 https://news.ycombinator.com/item?id=7866732
- pjmlp 7y agoThere are plenty of CS papers referring to reference counting as a GC implementation algorithm since Lisp exists.