Delphi - Recompiling application with 10.2.1 causes memory leaks?

Viewed 2393

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.

2 Answers

I have the same problem using C++Builder 10.2.1 in FMX and in VCL applications.

If I enable CodeGuard, I get memory leaks on application exit.

I have a TThread with OnTerminate handler: if I put a breakpoint in this handler, when I close the program it is never called.

If I put CheckSynchronize() in the destructor of my main application form, the problem remains.

My solution was a "horrible" loop like this in the destructor of the main form:

__fastcall TForm3::~TForm3(void) {
    for(int i = 0; i < 10; i++) {
        Sleep(1);
        CheckSynchronize();
    }
}

This solution is not deterministic but may be used in your application in debug mode to avoid CodeGuard error messages.

Another solution is using the WaitFor() function if MyThread is a TThread object:

MyThread = new MyThreadClass();

and DeleteThisTh() is a method of this class, we can wait for terminated thread inside DeleteThisTh():

void MyThreadClass::DeleteThisTh(void) {
    Terminate();
    WaitFor();
    delete this;
}

In the OnTerminate event, I can clean my objects. Take note:

  1. delete this is called after OnTerminate;
  2. DeleteThisTh() lives in the main thread;
Related