Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi Runtime error 216 thrown in SysUtils.FinaliseUnits, line number not in mapfile

I have a random Runtime Error 216 that appears on application close.

I have debugged as far as I can and the error is thrown in SysUtils.FinalizeUnits.

I have gone over the code and ensure all created objects are freed.

The number on the runtime error, 0040054A, is not present in the mapfile. Do you know what this means?

Can anyone tell me how to find out what is throwing the error?

like image 981
Jackie Avatar asked Mar 17 '11 07:03

Jackie


2 Answers

This is VERY OLD Delphi problem - wrong exception handling in unit initialization/finalization process.

The problem easy to reproduce - just make any program error/exception (division by zero for instance) in initialization block of any unit. The exception will be created correctly. But then, before the exception rise, the unit finalization process destroy the exception object. And thus, when the exception object accessed, the "runtime error 216" occured.

like image 147
Vasily Ivanov Avatar answered Oct 29 '22 22:10

Vasily Ivanov


I'd suspect a memory leak (all Runtime Errors 216 I've encountered so far were) and use a profiler (visual inspection is never as good as a tool). Since you're using Delphi XE, you should give AQTime a try (it's included), see also

Delphi - Check if memory is being released "on time"

Kind regards, Frank

like image 21
Frank Schmitt Avatar answered Oct 29 '22 22:10

Frank Schmitt