Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 672
Rohit Avatar asked Aug 09 '17 10:08

Rohit


People also ask

What could be the possible cause of memory leaks?

Memory leak occurs when programmers create a memory in heap and forget to delete it. The consequences of memory leak is that it reduces the performance of the computer by reducing the amount of available memory.

How do I find a memory leak in Delphi?

All that it takes to start working with it is add a single line in your project: ReportMemoryLeaksOnShutdown := True; And voilà, your application will report all memory leaks when it shuts down. If there are leaks at the end of your application, a dialog will be displayed showing all the leaks.

How do you avoid memory leaks?

Use reference objects to avoid memory leaks ref package, you can work with the garbage collector in your program. This allows you to avoid directly referencing objects and use special reference objects that the garbage collector easily clears. The special subclasses allow you to refer to objects indirectly.

What causes memory leaks in C?

Memory leaks occur when new memory is allocated dynamically and never deallocated. In C programs, new memory is allocated by the malloc or calloc functions, and deallocated by the free function.


1 Answers

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.

like image 116
Stefan Glienke Avatar answered Oct 12 '22 01:10

Stefan Glienke