I have an application that uses statically linked runtime packages, as well as development-time packages that use them. For some reason, the code in some section of the section completion section does not run at runtime (I cannot tell when this happened).
finalization ShowMessage('Goodbye'); end.
Disabling Delphi down shows a message, but not when my application shuts down. It gets weirder if I set a breakpoint on ShowMessage, it breaks there, but doesn't execute the line. If there are several lines in the finalization, the debugger stops in the first line, does not execute it, and then jumps to the end.
procedure ProcOne; begin SomeObject.Free; // Debugger does not enter or stop here SomeObject := nil; end; finalization ProcOne; // Debugger stops here, doesn't execute, jumps to "end." ProcTwo; // Every line has a blue dot ShowMessage('Bye'); end.
The call stack at the ProcOne checkpoint displays @ Halt0 => FinalizeUnits => MyPackage.MyUnit.Finalization.
If I include the device in an application that does not use packages, everything is done correctly.
Does anyone have an idea what could be causing this?
EDIT:
Thanks to Allen Bauer's remark pointing in the right direction, I managed to isolate the problem. It seems that the problem occurs if the application is built with a run-time package, and then dynamically loads another package, which also refers to this package and block.
I created a test project that demonstrates the problem: TestFinalization
Does anyone know the reason for this and / or the workaround? Usually you will not notice that your finalization is not performed until you notice that external resources are not cleared.