I do not think that this is really the resource that is critical, despite the phrase used. I think that it restores a resource, which may or may not be critical, and the quote may be rephrased, "assuming that the resource is freed."
If it is critical that the resource is freed at a certain point during program execution, after the object is unavailable, but before the resource is needed for any other purpose, the finalizer is inadequate. Instead, you need some kind of programming logic to make sure this is happening.
So file descriptors or db connections are crucial, if you are worried that you might end up, they are not critical otherwise. If you have reached some limit of open database connections, because the finalizers that close your old ones are not running yet, and you are trying to open another database connection, it will most likely fail. The memory situation is much better, because if you run out of memory due to inaccessible objects and try to create a new object, the GC will at least try to find something that can be completed and freed.
Thus, file descriptors and db connections must have a close() function that the user can call to free all resources in cases where program logic can determine that the object will no longer be used. The expectation that the GC to close the connection through the finalizer is not reliable enough. It also does a poor job of flashing a flash or crashing, although this is a separate issue.
source share