Search code examples
delphimemory-leaksdelphi-10.2-tokyo

Delphi - Recompiling application with 10.2.1 causes memory leaks?


I just installed Delphi 10.2 Release 1. When I recompiled my applications and ran them, I get a lot of memory leaks. I had no memory leaks with 10.2 (without the update). I made no changes to the code either.

To verify, I created a simple blank application and put a few components on the form. No code. Ran the application and got memory leaks reported. Memory leaks from the sample application

I wanted to highlight this (if only as a warning before you upgrade).

My questions:

  1. Has anyone else seen this issue?
  2. Is there something I need to or could be doing to get rid of this issue?

Note: I have logged an issue on quality portal, just in case this is a real issue: https://quality.embarcadero.com/browse/RSP-18774. In this ticket I have also attached the sample app.


Solution

  • After some investigation I found out that the callbacks being passed to TThread.CurrentThread.ForceQueue in TStyledControl.KillResourceLink are never executed because before any thread can handle them the application is ending and the TThread class destructor is destroying the list that still has unhandled callbacks.

    I solved this by adding a call to CheckSynchronize at the end of FMX.Forms.DoneApplication which forces the callbacks to be executed which resolved the huge memory leak.

    I don't know if this is the correct fix for the issue but it solved the memory leaks being reported.