TTaskBar memory leak

Embarcadero TTaskbar has a memory leak. Since I disabled this control in my form, FastMM reports a leak every time I close the application.

I tried disabling FastMM with this code:

procedure TMainForm.FormCreate(Sender: TObject); begin fastmm4.RegisterExpectedMemoryLeak(Taskbar); end; 

but that will not work. How to register this leak?


A memory block leak has occurred. Size 100

This block was allocated by 0xC64, and the stack trace (address return) at that time: 406A52 409A7B 409CAC 4283A0

[System.SysUtils] [System] [System.SysUtils.FmtStr] 409CC6 40D775 7628A65F
[Unknown function in StretchDIBits] 7731594E
[Unknown function in RtlpNtMakeTemporaryKey] 7731594E
[Unknown function in RtlpNtMakeTemporaryKey] 773168F8
[Unknown function in RtlpNtMakeTemporaryKey] 773168DC
[Unknown function in RtlpNtMakeTemporaryKey]

Currently, the block is used for an object of class: UnicodeString
Distribution Number: 2209

A memory block leak has occurred. Size: 36

This block was allocated by 0xC64, and the stack trace (return address) at that time: 406A52 407D43 40846A 42CD40
[System.SysUtils] [System] [System.SysUtils.Exception.CreateFmt] 5DEDD7
[System.Win.TaskbarCore] [System.Win] [System.Win.TaskbarCore.TTaskbarBase.UpdateTab] 610F00
[Vcl.Taskbar] [Vcl] [Vcl.Taskbar.CheckMDI] 5DF39F
[System.Win.TaskbarCore] [System.Win] [System.Win.TaskbarCore.TTaskbarBase.ApplyTabsChanges] 610DB8
[Vcl.Taskbar] [Vcl] [Vcl.Taskbar.TCustomTaskbar.Initialize] 5EB044
[Vcl.Forms] [Vcl] [Vcl.Forms.TApplication.Run] 62573A
[MinimalTemplate.dpr] [MinimalTemplate] [MinimalTemplate.MinimalTemplate] [26]

Currently, the block is used for an object of class: ETaskbarException
Accommodation number: 2207

Memory leaked in this application. Small block leaks (excluding the expected leaks recorded by the pointer):

21 - 36 bytes: ETaskbarException x 1
85 - 100 bytes: UnicodeString x 1
[Vcl.Forms] [Vcl] [Vcl.Forms.TCustomForm.SetVisible] 5F5010

+6
source share
1 answer

Memory leaked into this code from System.Win.TaskbarCore :

 procedure TTaskbarBase.UpdateTab; var LpfIsiconic: LONGBOOL; LHandle: HWND; LFlags: Integer; begin if FTaskbarIsAvailable then begin LHandle := GetFormHandle; if not FRegistered and TaskBar.RegisterTab(LHandle) then begin TaskBar.SetTabOrder(LHandle); TaskBar.SetTabActive(LHandle); FRegistered := True; end else ETaskbarException.CreateFmt(SCouldNotRegisterTabException, [TaskBar.LastError]); .... 

The last line throws an exception and then does nothing with it. The exception and the string it owns are leaking. According to FastMM.

You can register these objects as leaked if you can get their addresses. However, you cannot do this. You cannot reference this exception object.

If you just avoid this erroneous leak, and it makes sense, then you should include a fixed version of System.Win.TaskbarCore in the project. Make a copy of this file and add it to your project. Then change the code to fix the error. I assume it will look like this:

 if not FRegistered then begin if TaskBar.RegisterTab(LHandle) then begin TaskBar.SetTabOrder(LHandle); TaskBar.SetTabActive(LHandle); FRegistered := True; end else raise ETaskbarException.CreateFmt(SCouldNotRegisterTabException, [TaskBar.LastError]); end; 

Obviously, this needs to be reported to Embarcadero. I suggest you submit a bug report.


Another way is to try to avoid executing the dummy string altogether. I believe that if you remove this line from your .dfm file, you should avoid the dummy line and therefore avoid the leak:

 Visible = True 

Just delete this line, it seems to be a trigger.

Please note that I did this by reducing the project to its bare bones. To reproduce the problem, this is the minimum dfm file:

 object Form1: TMainForm Visible = True object Taskbar1: TTaskbar end end 

And with this dfm file there is no leak:

 object Form1: TMainForm object Taskbar1: TTaskbar end end 

Having reduced the project to the minimum minimum, I was able to find a trigger. I cannot stress how valuable this method of minimizing reproduction is.


Thanks to Remy for finding a quality control report for this error: QC # 128865

+10
source

Source: https://habr.com/ru/post/982731/


All Articles