View Issue Details

IDProjectCategoryView StatusLast Update
0020267LazarusLCLpublic2020-12-02 13:18
ReporterMarkus Müller Assigned ToBart Broersma  
Status closedResolutionunable to reproduce 
Product Version0.9.31 (SVN) 
Summary0020267: TSpeedButton.Glyph have a memory leak
DescriptionI use the TSpeedButton with showing small Pictures with the Glyph. I must often with TSpeedButton.Glyph.Assign(Bitmap) load a new picture.

But the old picture let the TSpeedButton in the memory.

After a litle work with this software comes the error "out of memory" and I must close and restart this software.
TagsNo tags attached.
Fixed in Revision
Attached Files



2011-09-17 16:57

reporter   ~0051949

Can you post sample application that shows the leak? I cannot reproduce on Windows XP SP3. Maybe you don't free the bitmaps you assign.

Markus Müller

2011-09-22 08:08

reporter   ~0052093

I have test it to reproduce in an small application, but I cannot. It work allways right.
In my program, there was this mistake an i must throw out the TSpeedButton and then it works good.

Flávio Etrusco

2011-09-22 11:13

developer   ~0052100

Will you still try to provide a sample application, or may I resolve as 'unable to reproduce'?

Markus Müller

2011-09-22 14:23

reporter   ~0052110

Yes, I have make a sample application, becouse my application have 30000 code lines. I cannot reproduce it in the sample application.

Here the sample code from me. In the Image1 have I store a picture.

  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    { private declarations }
    lst: TList;
    { public declarations }

  Form1: TForm1;


{$R *.lfm}

{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
Var i: Integer;
  btn: TSpeedButton;
  bmp: TBitmap;
  r: TRect;
  For i := 0 To 99 Do
    btn := TSpeedButton.Create(Self);
    btn.Parent := Self;
    btn.GroupIndex := 1;
    btn.Top := i;
    btn.Left:= i;
    bmp := TBitmap.Create;
    bmp.Width := Image1.Picture.Bitmap.Width Div 2;
    bmp.Height := Image1.Picture.Bitmap.Height Div 2;
    btn.Width := bmp.Width + 6;
    btn.Height := bmp.Height + 4;
    r.Left := 0;
    r.Right := bmp.Width;
    r.Top := 0;
    r.Bottom := bmp.Height;
    bmp.Canvas.StretchDraw(r, Image1.Picture.Bitmap);

procedure TForm1.Button2Click(Sender: TObject);
  While lst.Count > 0 Do

procedure TForm1.FormCreate(Sender: TObject);
  lst := TList.Create;

procedure TForm1.FormDestroy(Sender: TObject);


Zeljan Rikalo

2011-09-23 09:15

developer   ~0052121

@Markus, please attach complete app. Create "New Project", and add your code to unit1 of such project, then zip complete project and attach here.

Bart Broersma

2011-09-24 14:48

developer   ~0052145

Last edited: 2011-09-24 15:15

I uploaded a simplified example.
No need to have a TList.
No need to manually free all speedbuttons, since they are owned by the form (which will free them on destruction).

Based upon your original report (having to assign glyphs more then once), I adjusted the code a little.
First I assign the bitmap form Image1, then I assing the bitmap from Image2 to the glyph.

Tested with Lazarus 0.9.31 r31810M and r32450M (FPC 2.4.4 i386-win32-win32/win64) and I can see no memory leak when compiling with heaptrace eneabled (-gh):

Heap dump by heaptrc unit
14027 memory blocks allocated : 4649954/4667296
14027 memory blocks freed : 4649954/4667296
0 unfreed memory blocks : 0
True heap size : 294912 (96 used in System startup)
True free heap : 329712
Should be : 294816

So, unless you can provide a (minimal test-case) example demonstrating the memory leak, this issue wil be closed as "unable to reproduce".

2011-09-24 15:12 (142,830 bytes)

Bart Broersma

2011-10-22 16:30

developer   ~0053281

Please re-open if you can provide a minimal test-case like described in my previous note.

Issue History

Date Modified Username Field Change
2011-09-16 08:31 Markus Müller New Issue
2011-09-16 08:31 Markus Müller Widgetset => Win32/Win64
2011-09-17 16:57 cobines Note Added: 0051949
2011-09-22 08:08 Markus Müller Note Added: 0052093
2011-09-22 11:13 Flávio Etrusco LazTarget => -
2011-09-22 11:13 Flávio Etrusco Note Added: 0052100
2011-09-22 11:13 Flávio Etrusco Status new => feedback
2011-09-22 14:23 Markus Müller Note Added: 0052110
2011-09-23 09:15 Zeljan Rikalo Note Added: 0052121
2011-09-24 14:45 Bart Broersma File Added:
2011-09-24 14:48 Bart Broersma Note Added: 0052145
2011-09-24 14:59 Bart Broersma Severity crash => minor
2011-09-24 15:07 Bart Broersma File Deleted:
2011-09-24 15:07 Bart Broersma File Added:
2011-09-24 15:12 Bart Broersma Note Edited: 0052145
2011-09-24 15:12 Bart Broersma File Deleted:
2011-09-24 15:12 Bart Broersma File Added:
2011-09-24 15:15 Bart Broersma Note Edited: 0052145
2011-10-22 16:30 Bart Broersma Status feedback => resolved
2011-10-22 16:30 Bart Broersma Resolution open => unable to reproduce
2011-10-22 16:30 Bart Broersma Assigned To => Bart Broersma
2011-10-22 16:30 Bart Broersma Note Added: 0053281
2020-12-02 13:18 Markus Müller Status resolved => closed