View Full Version : EurekaLog Viewer memory leak?
RHabedank
11-Feb-2006, 03:54 PM
When using EurekaLog Viewer I've noticed that application's memory usage seems to rise each time you load a new .elf file. It keeps climbing, no matter the size of the .elf file.
I looked at the EGeneralData.pas unit and it appears there is a memory leak - in compiling and running it with FastMM4, a leak is reported for every record loaded.
I'm wondering if the TGeneralDataSet.Delete procedure shouldn't look something like:
procedure TGeneralDataSet.Delete(Index: Integer);
var
PRecord: PGeneralDataRecord;
Ptr: Pointer;
i : Integer;
begin
Ptr := Items[Index];
PRecord := PGeneralDataRecord(Ptr);
Finalize(PRecord^.FieldsValue); // clean up memory consumed by Variants
PRecord^.Details.Free;
FreeMem(Ptr); // release memory for record
inherited;
end;
I'm no expert on Variants, so am unsure if the "Finalize" piece needs to be there - the Delphi docs are not clear to me whether a static array of Variants is automatically cleaned up.
Regards,
Rich Habedank
admin
13-Feb-2006, 10:02 AM
Hi,
RHabedank wrote:
> When using EurekaLog Viewer I've noticed that application's memory usage
> seems to rise each time you load a new .elf file. It keeps climbing,
> no matter the size of the .elf file.
>
> I looked at the EGeneralData.pas unit and it appears there is a memory
> leak - in compiling and running it with FastMM4, a leak is reported for
> every record loaded.
>
> [...]
>
> I'm no expert on Variants, so am unsure if the "Finalize" piece needs
> to be there - the Delphi docs are not clear to me whether a static
> array of Variants is automatically cleaned up.
>
> Regards,
>
> Rich Habedank
Thank you for the good feedback.
I have just found and fixed it.
The following fix will be available in the next EurekaLog 5.1.3
procedure TGeneralDataSet.Delete(Index: Integer);
var
PRecord: PGeneralDataRecord;
Ptr: Pointer;
begin
Ptr := Items[Index];
PRecord := PGeneralDataRecord(Ptr);
PRecord^.Details.Free;
Dispose(Ptr);
end;
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!
RHabedank
13-Feb-2006, 04:50 PM
Fabio,
I tried your posted fix, compiled with FastMM4 in full debug mode. It appears that the variants are not being freed with the call to Dispose, as FastMM4 now reports memory leaks for each of the variant fields that was used. Previously, the memory leak was reported as one entry per dataset record, while this latest test is being reported as one entry per variant field. While my D7 documentation says that Dispose is preferred over FreeMem and that there is no need to explicitly call Finalize when using Dispose, the results of my tests seem to contradict that.
When I put the line
Finalize(PRecord^.FieldsValue);
back in the code, keeping the Dispose portion of your fix, FastMM4 no longer reports any memory leaks and Task Manager's Processes | Mem Usage field (yeah, I know it's not very accurate) does drop as might be expected when the dataset is cleared. I used some large .elf files for testing so the changes in memory consumption would be significant.
Another test I did called the viewer's main form from a new, blank main form with a button to create and display the viewer main form, which showed me what happens when the viewer form closes down.
Regards,
Rich Habedank
admin
14-Feb-2006, 10:13 AM
Hi,
RHabedank wrote:
> Fabio,
>
> I tried your posted fix, compiled with FastMM4 in full debug mode. It
> appears that the variants are not being freed with the call to Dispose,
> as FastMM4 now reports memory leaks for each of the variant fields that
> was used. Previously, the memory leak was reported as one entry per
> dataset record, while this latest test is being reported as one entry
> per variant field. While my D7 documentation says that Dispose is
> preferred over FreeMem and that there is no need to explicitly call
> Finalize when using Dispose, the results of my tests seem to contradict
> that.
>
> When I put the line
>
> Finalize(PRecord^.FieldsValue);
>
> back in the code, keeping the Dispose portion of your fix, FastMM4 no
> longer reports any memory leaks and Task Manager's Processes | Mem
> Usage field (yeah, I know it's not very accurate) does drop as might be
> expected when the dataset is cleared. I used some large .elf files for
> testing so the changes in memory consumption would be significant.
>
> Another test I did called the viewer's main form from a new, blank main
> form with a button to create and display the viewer main form, which
> showed me what happens when the viewer form closes down.
>
> Regards,
>
> Rich Habedank
Yes, it's true! :)
I have checked and reintroduced the Finalize call!
Thank you for your good feedback. :)
--
Best regards...
Fabio Dell'Aria.
----------------
http://www.eurekalog.com
Catch every BUG, every time!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.