Recent

Author Topic: Icon.Assign(Bitmap) memory leak  (Read 2154 times)

Nevada Smith

  • New Member
  • *
  • Posts: 20
Icon.Assign(Bitmap) memory leak
« on: April 16, 2017, 09:35:33 pm »
Hi,
I am creating a countdown timer. The progress of the timer is shown by changing the system tray icon, form icon and the application icon. As the timer progresses, the user will be able to have a glance at the system tray or the task bar to get an idea on how far the timer has progressed.

I have an array of TBGRABitmaps created, 24 of them for tray icon (small ones), 24 more for form and application icons (larger ones). And I am using Icon.Assign to change the icon. I see that this is causing a steady memory leak.

Code: Pascal  [Select][+][-]
  1.       FForm.tiMain.Icon.Assign(FTrayProgressBitmaps[Index + 1].Bitmap);
  2.       FForm.Icon.Assign(FAppProgressBitmaps[Index + 1].Bitmap);
  3.       Application.Icon.Assign(FAppProgressBitmaps[Index + 1].Bitmap);
  4.  

When  I comment out Icon.Assign statements, the leak seem to vanish. What is the way out?
(I have looked at other thread and have so far tried (a) Draw into the canvas of the icon, it causes a segfault (b) assign icon handles, this does not seem to do anything)

Nevada Smith

  • New Member
  • *
  • Posts: 20
Re: Icon.Assign(Bitmap) memory leak
« Reply #1 on: April 17, 2017, 11:07:54 am »
I think I have figured it out. I am no expert, hence the solution that I am suggesting must be considered with appropriate caution.

Icon.Assign(Bitmap) almost always involves creation an icon (or some associated object) on the fly. If you do this often enough, the application will have noticeable leaks. Icon.Assign(Icon) apparently does not have that problem.

In my case, instead of having an array of TBGRABitmaps, I changed it to an array of TIcons. Then for each TIcon, started with creating TBGRABitmap, drew on it and finally assigned it to the TIcon. It is this icon which is then assigned ot the tray, form or application icons. No observable leak after this.

 

TinyPortal © 2005-2018