7 ms·
Garbage collection could prove to be a dead end. Rust and Swift are prospering as the latest cool things because they don't have any. Decades from now we may be
by WildUtah 10y ago
Garbage collection could prove to be a dead end. Rust and Swift are prospering as the latest cool things because they don't have any. Decades from now we may be hearing about garbage collection as a vastly expensive experiment that simply didn't pan out.
The clever combination of declarative management for common cases and reference counting for complicated cases looks like the winner in the long run.
- justin66 10y ago> Garbage collection could prove to be a dead end. You'd have to elaborate on that an awful lot to be at all persuasive. > Rust and Swift You were comparing C++ to Python and Ruby. We're talking two different paradigms here.
- deleted 10y ago[deleted]
- pjmlp 10y agoSwift surely has garbage collection. Reference counting is a garbage collection algorithm.
- sqeaky 10y agoIn that case C++ has garbage collection too with std::shared_ptr. I guess 1 is a count too so also with std::unique_ptr.
- WildUtah 10y agoIndeed, according to these "ref counting is gc" folks, free(void *) is a garbage collector, so C has always been garbage collected since 1970.
- pjmlp 10y agoNo, because the language C doesn't provide any of the algorithms described here: http://gchandbook.org http://gchandbook.org Although, there are conservative GCs for C that replace malloc () and make fre () a nop, they cannot release all memory properly due to C semantics.
- sqeaky 10y agoI am pretty WildUtah was being sarcastic to be a more extreme version of my post. Or perhaps it was an attempt to expand the grey area.
- hellofunk 10y agoAnd technically, also unique_ptr, which has a reference count of 1 or 0.
- pjmlp 10y agoC++ has a GC ABI introduced in C++11 and the dialects C++ Builder, C++/CLI and C++/CX do have GC support at language level. Library types like std::shared_ptr don't really count to say that a language has a GC, because their use, specially their correct use, is not enforced by the compiler.
- srssays 10y agoYou can't just redefine a word that a person has already defined (albeit implicitly), in order to make them wrong. That's not how being right on the internet works. If you want to be right on the internet, you have to define the word before they do.
- toomim 10y agoHe's not redefining it. It was defined in the 70s. https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)#Reference_counting https://en.wikipedia.org/wiki/Garbage_collection_(computer_s... Reference counting is definitely a method of garbage collection.
- Ace17 10y agoThis is just terminology. The important question here is: "Can your program leak memory?"
- hellofunk 10y agoThe risk of memory problems don't disappear because of any form of GC. The problems are just different, and leaks are still quite possible.
- gozur88 10y agoThey're possible, but not nearly as common. Back when I was coding C++ full time I spent most of my debugging time chasing down memory leaks and out-of-scope variables. Then in a decade of Java programming I think I had one memory leak.
- hellofunk 10y agoBut that's a two-edged sword. Many Java developers, especially those recently out of school, who have never had a C or C++ background, think the GC is a magical blanket that takes care of everything, and as a consequence they don't have an intuitive grasp of the true costs of memory. They just throw things around like it's no big deal. I've interacted with a lot of C++ developers who were hired to rewrite large Java applications in C++ for performance reasons, when really Java could have handled it if only the developers understood memory better. GC is an abstraction that can work well but can also interfere with how a developer thinks.
- hellofunk 10y agoThen C++ is also garbage collected.
- pjmlp 10y agoKind of, but only because C++11 defined a pluggable GC ABI. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2670.htm http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n267... Also, there are the C++/CLI and C++/CX that support GC at language level. Now std::*_ptr<> types don't count to make the language GC, because their use is not enforced by the compiler.
- hellofunk 10y ago> Now std::*_ptr<> types don't count to make the language GC, because their use is not enforced by the compiler. Then you also shouldn't say that Swift is garbage collected.
- pjmlp 10y agoSwift RC is managed by the compiler and is visible in the type system and language semantics. C++ language definition doesn't give any special treatment tostd::*_ptr<> types regarding compiler semantics. They could be be something else.
- hellofunk 10y agoOnly partially, in Swift, it is still up to the user to cleverly work around scenarios that the system does not catch. Which is why you have weak references and other many tricks in the language to circumvent infinite reference cycles and related problems. It's hard to call language garbage collected when you have to deal with all that stuff yourself. Just look at the stuff you have to do sometimes in your closures to avoid them creating memories leaks.
- int_19h 10y agoWhy should it be enforced by the compiler? We're talking about garbage-collected languages (and "language" traditionally includes the standard library), not garbage-collected-only languages. I mean, by your definition, C# also doesn't count, because it has unmanaged pointers in it.
- lispm 10y agoI add the remark here: in some literature, especially older, Reference Counting is not listed under Garbage Collection, but under Automatic Memory Management or Automatic Storage Reclamation. See page 6, remark 7 in 'Uniprocessor garbage collection techniques', Paul Wilson: http://scholarworks.rit.edu/cgi/viewcontent.cgi?article=1322&context=other&sei-redir=1 http://scholarworks.rit.edu/cgi/viewcontent.cgi?article=1322...