Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy code in any unit finalization section of a package is not executed at shut down?
    primarykey
    data
    text
    <p>I have an application that uses statically-linked runtime packages as well as designtime packages that use them. For some reason the code in any unit finalization section is not being run at runtime (I can't tell when this started happening).</p> <pre><code>finalization ShowMessage('Goodbye'); end. </code></pre> <p>Shutting Delphi down shows the message, but not when my application shuts down. It gets weirder in that if I put a breakpoint on ShowMessage, it breaks there but does not execute the line. If there are multiple lines in the finalization, the debugger stops on the first line, does not execute it and then jumps to the end.</p> <pre><code>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. </code></pre> <p>The call stack on ProcOne breakpoint shows @Halt0 => FinalizeUnits => MyPackage.MyUnit.Finalization.</p> <p>If I include the unit in an application that doesn't use packages, everything executes properly.</p> <p>Does anyone have an idea what could be causing this?</p> <p>EDIT:</p> <p>Thanks to Allen Bauer's comment pointing in the right direction, I have managed to isolate the problem. It seems the problem arises if an application is built with a runtime package, then dynamically loads another package that also references that package and unit.</p> <p>I have created a test project that demonstrates the problem: <a href="https://skydrive.live.com/redir.aspx?cid=921fe63c7cf3618b&amp;resid=921FE63C7CF3618B!105" rel="nofollow">TestFinalization</a></p> <p>Does anyone know the reason for this and/or a workaround? You normally might not notice that your finalization is not being run until you notice that external resources are not being cleaned up.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload