Is memory leak possible with LoadIcon ()?

I use this code to animate the tray icon in the file (icon1 and icon2 are in the .res file):

while AnimationPending do
begin
    TrayIcon.Icon.Handle := LoadIcon(hInstance,'icon1');
    Sleep(300);
    TrayIcon.Icon.Handle := LoadIcon(hInstance,'icon2');
    Sleep(300);
end;

I have a fear that it could create a memory leak if I do this in a loop because icon1 / 2 loads over and over again.

Does the code create a memory leak or is it safe to use it in a loop?

+5
source share
1 answer

You are calling LoadIcon. This returns the so-called common icons. This is explained in the documentation for DestroyIcon. One of the consequences of using a common icon is that you do not need to call DestroyIcon.

DestroyIcon : CreateIconFromResourceEx ( LR_SHARED), CreateIconIndirect CopyIcon. , . , , . .

  • LoadIcon
  • LoadImage ( LR_SHARED)
  • CopyImage ( LR_COPYRETURNORG, hImage )
  • CreateIconFromResource
  • CreateIconFromResourceEx ( LR_SHARED)

, ? ,

TrayIcon.Icon.Handle := LoadIcon(hInstance,'icon1');

Handle TIcon. TIcon , . , TIcon . , DestroyIcon . , MSDN , . .

, , , . CreateIconIndirect, . , TIcon .

, . , , !

:

  • LoadIcon . . TrayIcon.Icon.Handle.
  • LoadIcon . , , , . . , SM_CXSMICON SM_CYSMICON.
+8

All Articles