is it really okay in Delphi to execute code after the inherited call in a destructor?
You can find this in System.Classes:
destructor TThread.Destroy;
begin
[...]
inherited Destroy;
FFatalException.Free;
end;
I think, that accessing an instance member after calling the inherited Destroy method is a bad idea.
It is perfectly safe to execute code after a call to an inherited destructor, so long as that code does not rely on something that has been destroyed by that inherited destructor. In the same way it is safe to execute code before a call to an inherited constructor, so long as the code does not rely on anything instantiated in that inherited constructor.
But it is certainly true that this is not good style. There are on occasions reasons that would lead you to such code, but usually such reasons should be taken as indication that something is wrong in your design.
In the example that you give there is simply no need to write the code that way. The call to FFatalException.Free
could perfectly well happen before the call to the inherited destructor.
The instance is not removed from memory by the destructor method itself but by the call of TObject.FreeInstance
TObject.FreeInstance
is called, because a destructor is called, after processing the destructor code.
BTW: It is the same to the constructor. The instance is created by class function TObject.NewInstance : TObject
and it is called before the constructor is called (just because it is a constructor)
Because of this, you will have a valid instance inside the whole constructor or destructor code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With