...The GC was never meant to manage resources; it was designed to manage memory allocation ...
In the specific case of database connections, you are dealing with other resources than just memory... (Scott Dorman)
The OP didn't tag with a specific platform, though most of the answers have been .net-specific, noting that GC is mainly for avoiding memory leaks, but extensions such as using
expressions and IDisposable
can help a lot.
Other platforms offer other solutions. For example, in C++, there is no (built-in) garbage collection, but some forms of shared pointers can be used to help with memory management, and the RAII-style of coding can be extremely helpful in managing other types of resources.
In cPython, two different garbage collection systems are used. A referencing counting implementation immediately calls destructors when the last reference is deleted. For common "stack" objects, this means that they get cleaned up immediately, like what happens for C++ RAII objects. The downside is that if you have a reference cycle, the reference counting collector will never dispose of the object. As a result, they have a secondary non-deterministic garbage collector that works like Java and .NET collectors. Like .NET with its using statements, cPython tries to handle the most common cases.
So, to answer the OP, non-deterministic garbage collection helps simplify memory management, it can be used to handle other resources too as long as timeliness isn't an issue, and another mechanism (such as careful programming, reference counting GC, a using statement, or real RAII objects) are needed when timely releasing of other resources is needed.