On Thursday, 8 October 2015 at 15:51:44 UTC, Ola Fosheim Grøstad wrote:
So I don't think there are _good_ reasons to call finalizers/destructors on the GC heap, it's a sign of a bad model where the responsibilities are unclear. GC objects should only "own" memory on the GC heap.

As far as I can tell, finalizers are for when you either really don't care when a non-GC resource gets cleaned up (which is probably a bad design in any program that isn't fairly small) or for cleaning up after you screw-up and you forget to call the appropriate function on the object to tell it to free those resources (be it call dispose or something else). In general, finalizers are a sign of a problem. If all you have is the GC heap, or if you need to be able to put an object that needs to clean-up a non-GC resource inside of an object on the GC heap, then you're kind of stuck, in which case, you do manual resource cleanup and have a finalizer as backup, but it's definitely a bandaid rather than an ideal solution. The potential need for finalizers is definitely a con to dealing with a GC.

- Jonathan M Davis

Reply via email to