But for me, the real folly is that memory isn't the only resource. You have file handles, sockets, ... all sorts of things |
Very old line of argumentation, and debunked many times in countless GC vs manual MM rants.
Memory isn't the only resource, but it is the resource that is used most of time. I am sure more than 99.999% of my objects are memory-only resources. :P And unlike many other resources memory is: stateful and shared. Which is the worst combination that can be. Just look at the topics on this forum - most of the problems related to resource management are memory-related problems, not e.g. file-related problems. When I read from file, I just open it somewhere, read the data into memory and close it near the place that has opened it. So the problem of managing such resources is well isolated to a small piece of code. The rest of the code doesn't operate on the file descriptor directly - it operates on data read from that file into the memory.
And in GCed environments you can have RAII-like behaviour too - in some of them it is not any more complex to achieve than in C++ (if you can't do it it is a problem of your crappy GCed language, not GC itself).
Heaven forbid the designer should be forced to think. |
The design of proper interfaces is hard enough that making it even more complex can sometimes be just "too complex". And you know what happens when people deal with APIs that are too complex? Bugs, bugs, bugs... Interface should be only an interface - it should be as much independent from the underlying implementation as possible. GC allows to do it better. You asked what GC is a solution to. I answered. Just it. It simplifies modular design. Things like Eclipse where you have enormous number of plugins, that provide sometimes core functionality, would be extreme pain to make in a non GCed environment.
BTW: Do you think adding shared_ptr, a poor-man's GC, to Boost was pointless? Or people like H. Boehm wasted their time creating things like BDW? (ok, it is still a poor-man's GC compared to platforms designed with GC from ground up, but whatever, it is slow, but it works).