3 ms·
Well, to stay with the example of file handles, one might forget to explicitly close the file. The finalizer would then act as a safety net and close the file a
by wladimir 15y ago
Well, to stay with the example of file handles, one might forget to explicitly close the file. The finalizer would then act as a safety net and close the file as soon as the object is garbage collected.
But indeed, it is a very bad idea to rely on that. Even in languages that have reference-counting garbage collection semantics (such as Python) it is recommended to explicitly close files, as someone might still have a reference around.