Many of our customers today write FireMonkey Windows applications. We recently got some customer reports on FMX memory leaks on Windows using RAD Studio 10.2 Release 1 (or Tokyo Release 1). The issue is reported at https://quality.embarcadero.com/browse/RSP-18774 and https://stackoverflow.com/questions/45588741/delphi-recompiling-application-with-10-2-1-causes-memory-leaks.
If you encounter such issues after installing 10.2.1, we recommend trying the workaround below. We will address this issue in the future.
To our knowledge, the memory leak doesn’t happen during program execution, but on termination because a cleanup thread does not excute in time. Delphi MVP Stefan Glienke suggested a relatively simple workaround both on the Quality Portal bug report and in the StackOverflow page linked above. By calling
CheckSynchronize
(from System.Classes) you can have the application wait for the cleanup threads to execute. This does a quick sync, but does not cause any noticeable delay.
There are different places where you can put this code, but the simplest one for me is a finalization block in the main form source code (no need to update the library units). This is an example of the code added to the end of the main form unit, along with activating memory leak reporting:
Another very good suggestion is to change the project file (the .dpr file), but your mileage might vary — you can also consider fixing the library as this will fix all of your applications at once.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
I have the same issue with Delphi XE5, but it seems CheckSynchronize does not work for Delphi XE5. Is there other way to fix it?
CheckSynchronize
has existed since Delphi 6 / C++Builder 6. If you’re finding it doesn’t work, then it is possible the logic you’re implementing is not correct.