4 ms·
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
by coldcode 10y ago
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.
- pjmlp 10y agoSwift has a garbage collector. https://www.amazon.com/Garbage-Collection-Algorithms-Automatic-Management/dp/0471941484 https://www.amazon.com/Garbage-Collection-Algorithms-Automat... Check chapter 5.
- kibwen 10y agoI 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.
- pjmlp 10y agoBoth 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.
- azinman2 10y agoTo me, a true garbage collector means any cyclic references can be cleared. That is not the case in Swift... you can still leak memory.
- pjmlp 10y agoWhich 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.
- azinman2 10y agoThat 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.
- ungzd 10y agoC++'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.
- pjmlp 10y agoActually 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-Automatic-Management/dp/0471941484 https://www.amazon.com/Garbage-Collection-Algorithms-Automat...
- gpderetta 10y ago> 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.