Page 1 of 1

Small Memory Leak in TBrushDialog

Posted: Mon Jun 18, 2007 10:53 am
by 9340302
The private procedure TBrushDialog.LStyleDrawItem calls GetInternalBrush, which creates a TBitmap object that is never freed.

Posted: Mon Jun 18, 2007 3:24 pm
by narcis
Hi pemar13,

This is a function that returns an object. Who makes the call has to free the object and this is already done everywhere this method is called.

Anyway, if you think you have found a memory leak in TeeChart please send us a simple example project we can run "as-is" to reproduce the problem here and we will try it with a profiler.

You can either post your files at news://www.steema.net/steema.public.attachments newsgroup or at our upload page.

Thanks in advance.

Posted: Fri Jun 22, 2007 12:35 pm
by 9340302
Hi Narcis,

Yes, TBrushDialog.GetInternalBrush is a function that returns an object that has to be freed by the caller.

No, this is NOT done everywhere this method is called.

If you take a look at TBrushDialog.LStyleDrawItem, line 296 of the 7.11 version of TeeBrushDlg.pas you will find the code

StretchDraw(Rect,GetInternalBrush(Index-8))

which clearly cannot free the object created by GetInternalBrush.

Of course, I could spend the time to create and upload a simple example project that illustrates the memory leak so that you can run a profiler.
In this obvious case, however, I believe that you by simply taking a look at the mentioned code will come to the same conclusion as me, saving both my time and yours.

Posted: Fri Jun 22, 2007 1:59 pm
by narcis
Hi pemar13,

Thanks for the information, but in TeeChart Pro v8 VCL, version released earlier this week, this method contains this code snippet:

Code: Select all

      if Index>7 then
      begin
        tmp:=GetInternalBrush(Index-8);
        try
          StretchDraw(Rect,tmp);
        finally
          tmp.Free;
        end;
      end
      else
         FillRect(Rect);
This mean the returned object from GetInternalBrush is assigned to tmp variable and this is already freed at tmp.Free call.

You may want to implement something similar in your v7 sources.

Posted: Mon Jun 25, 2007 8:00 am
by 9340302
Thanks Narcis, please see new post about TeeChart 8 bugfixes