Memory Leak in Windows 10 TNotification in Delphi Seattle?
Asked Answered
T

1

8

I'm implementing Windows 10 Notification in my application. However, the code below (which runs fine) apparently give a memo leak of 1 TNotification object and 2 strings, yet I free the object at the end of the block:

aNotification := NotificationCenter.CreateNotification;

//-- If not assigned then must be Win 8.1 or below
if not assigned(aNotification) then
  exit;

try
  aNotification.Title := AlignMixVersionName + ' License';
  aNotification.AlertBody := aText;

  NotificationCenter.PresentNotification(aNotification);

finally
  aNotification.Free;
end;

Am I doing something stupid or is there a memory leak in the implementation of Notifications?

  • Steve
Trichromatism answered 30/3, 2016 at 13:41 Comment(4)
what is the value of aNotification after NotificationCenter.PresentNotification(aNotification) ?Quentin
@HughJones aNotification is still assigned after PresentNotification - so strange.Trichromatism
I did Delphi many moons ago and remember setting things to nil ... aNotification := nil;Leilanileininger
There was an issue opened for this mem leak in RAD Studio's issue tracker: quality.embarcadero.com/browse/RSP-17660Bulldoze
C
8

It is indeed a leak caused by TNotificationCenterDelegateActivated. In its Create a copy of the TNotification parameter is created, but never freed.

Seems like some developers responsible for this code are not that proficient with non-ARC environments.

Cottier answered 30/3, 2016 at 15:1 Comment(10)
Thanks for confirming.Trichromatism
Would be great to QC this at Emba.Dashtikavir
Naively one might expect Emba to have tests for their libraries that would flush out leaks. How hard could it be?Constable
@DavidHeffernan Naively one might expect they have a simple app to test and the very first line of written code is ReportMemoryLeaksOnShutdown := true;.Haroun
@UweRaabe - does that mean we have very little hope of a positive result?Quentin
@HughJones, No - merely the opposite.Cottier
@UweRaabe - what does 'ARC' stand for?Quentin
@HughJones, ARC = Automated Reference Counting. It is a new feature of the Delphi mobile compilers. Sometimes features are developed for mobile first and then ported to Win32 and Win64. That is where such errors creep in.Cottier
@UweRaabe - so is it the same as 'Garbage Collection'? (not to worry - I found this : blog.marcocantu.com/blog/…)Quentin
@Hugh No it is different from garbage collectionConstable

© 2022 - 2024 — McMap. All rights reserved.