Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One thing I don't miss now writing in Swift is a garbage collector. Are there other languages that do something similar to Swift? It seems most languages either use a GC of some kind or make you do your own heap management.


Swift has a garbage collector.

https://www.amazon.com/Garbage-Collection-Algorithms-Automat...

Check chapter 5.


I think it's both fair to say that reference counting is a form of garbage collection (dynamic lifetime determination is dynamic lifetime determination), but also remark that reference counting has notably distinct performance characteristics (some good, some bad) compared to a tracing collector.


Both being GC algorithms, what one should discuss is implementation advantages and disadvantages of each algorithm.

Just like sorting or graph navigation algorithms get discussed, for example.

However somehow we get this pop culture of GC vs RC instead.


To me, a true garbage collector means any cyclic references can be cleared. That is not the case in Swift... you can still leak memory.


Which is not true if a data structure happens to have a strong reference, like in a cache or event handler, thus "leaking" in a true garbage collector.


That doesn't defeat the definition of a garbage collector. You wouldn't then say no GC exists... but in the case of no inbound references then that's memory that can definitively be cleared.


C++'s shared_ptr (not a language feature but in standard library), Python (has GC but only for detecting cycle references AFAIK), Perl, PHP. Lots of OOP libraries for C: COM, GLib. RC, ARC in Rust.


Actually C++ got a tracing GC API in C++11.

As for the rest, RC is GC.

Check chapter 5 in one of the most widely academic accepted books about GC algorithms.

https://www.amazon.com/Garbage-Collection-Algorithms-Automat...


> Actually C++ got a tracing GC API in C++11.

Technically true, but in reality it is just a token effort to please Hans Bohem and get him to focus on designing the C++ concurrent memory model instead :).

As of today, I don't think any implementation actually offers optional GC, so those functions are alway just trivially implemented.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: