3 ms·
We can separate that into the question: is there a good reason to have user-defined finalizers? Because there is clearly value in doing certain very specific t
by kazinator 12y ago
We can separate that into the question: is there a good reason to have user-defined finalizers?
Because there is clearly value in doing certain very specific things when objects become unreachable.
The same mechanism on which finalizers are built does useful things like expire entries out of weak hash tables or "lapse" weak references to safe values.
Now suppose you have some special baggage ("external resources") associated with weak hash table entries. You'd like to dispose of it when the entries disappear. That looks like a very good case for extending the finalization mechanism with user-defined hooks.