On 28/08/14 21:27, "Marc Schütz" <[email protected]>" wrote:
The other way round would be safer: A destructor automatically calls as its first step a finalizer (let's use that term for a destructor called by the GC) if present, but a finalizer doesn't call the destructor. Remember that the things that are forbidden in a finalizer are usually fine in normal destructors. By calling the destructor from inside the finalizer, you bring all the problems back that you wanted to get rid of by introducing a special finalizer, right? And this would be backwards-compatible: There is already today no guarantee that a destructor gets called by the GC, so never calling it doesn't break any valid code, strictly speaking. Then you could place "safe" cleanup actions (like closing a file) into the finalizer, and "unsafe" ones (like removing yourself from a linked list) into the destructor, and you don't need to duplicate the actions from the finalizer in the destructor. The compiler might then even detect unsafe operations in the finalizer and refuse to compile them.
Yeah, you're probably right. I got it all backwards. -- /Jacob Carlborg
