5 ms·
No, absolutely not. Swift uses reference counting under the hood because of its Objective-C runtime ties, not because reference counting is better than tracing
by moon_priestess 10y ago
No, absolutely not. Swift uses reference counting under the hood because of its Objective-C runtime ties, not because reference counting is better than tracing garbage collection. The author is just not well-informed on that issue.
- seanmcdirmid 10y agoTracing GC was supported in objective C for awhile but was deprecated/dropped awhile back because of performance issues. Referencing counting does have some advantages over tracing GC, but it's all really a bunch of trade offs to make.
- pjmlp 10y agoPerformance wasn't the main problem, rather crashes and memory corruption. https://news.ycombinator.com/item?id=12589998 https://news.ycombinator.com/item?id=12589998
- seanmcdirmid 10y agoAh, that makes sense. I remember them putting it in and then yanking it out for some reason. Referencing counting seems to be in vogue these days because it is somewhat more predictable on mobile systems, at least this is what I heard about the Metro/Store/UWP API at Microsoft (C# is still garbage collected, but the APIs are primarily ref counted).
- pjmlp 10y agoWinRT is just COM with a new base interface extending IUknown and .NET metadata instead of TLB files. If you search for Ext-VOS on Don Syme blog, it resembles quite a lot the genesis of .NET before they went with the CLR.
- kbsletten 10y agoI would say that in the specific case of this article (talking about passing pointers to managed objects to C) it is easier without a tracing GC simply because reference counting doesn't ever move the object and so pointers won't be broken (except, as the author shows, if you let the only reference go out of scope before you're done using the pointer). A GC language _may_ implement pinning to overcome this, but not all do.
- stjepang 10y agoChris Lattner on the advantages of reference counting over tracing garbage collection: https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160208/009422.html https://lists.swift.org/pipermail/swift-evolution/Week-of-Mo...
- coldtea 10y ago>Swift uses reference counting under the hood because of its Objective-C runtime ties, not because reference counting is better than tracing garbage collection Not really. Obj-C already had a GC and dropped it, to implement ARC because it's faster and more memory efficient.
- pjmlp 10y agoCompletely wrong. GC was dropped from Objective-C, because Apple did not manage to make it work safely with C semantics. Objective-C developers weren't able to mix Frameworks compiled with and without GC, there were lots of corner cases and forum discussions regarding GC runtime crashes were quite common. Apple's decision in such scenario was to take the alternative route to make the compiler do what the Cocoa manual reference counting patterns already required. Nothing to do with being faster and more memory efficient, rather having something in Objective-C that would work at all. However this urban myth keeps being repeated.
- Joky 10y agoIt's OK to point something as "Completely wrong" and as a "Urban myth", but a source is appreciated.
- pjmlp 10y agoThe source are the Apple developer forums and WWDC sessions.
- coldtea 10y agoHow about Chris Lattner, who implemented that in Obj-C and then Swift? >>Has a GC been considered at all? >GC [also] has several huge* disadvantages that are usually glossed over: while it is true that modern GC's can provide high performance, they can only do that when they are granted much more memory than the process is actually using. Generally, unless you give the GC 3-4x more memory than is needed, you’ll get thrashing and incredibly poor performance. Additionally, since the sweep pass touches almost all RAM in the process, they tend to be very power inefficient (leading to reduced battery life). I’m personally not interested in requiring a model that requires us to throw away a ton of perfectly good RAM to get an “simpler" programming model - particularly on that adds so many tradeoffs.* So it's hardly "completely wrong", especially for iOS.
- mikeash 10y agoSwift also uses reference counting because the people at Apple think it's outright better, not just because of the Objective-C heritage. Whether they're correct is certainly debatable, but it's not a compromise in their view, it's the best choice.