Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

RB14.03. Memory leak in TppViewer.DoOnPageChange;

edited March 2012 in General
Hello everybody.

I think that I (actually it was FastMM) has just found a memory leak in
TppViewer.DoOnPageChange.

procedure TppViewer.DoOnPageChange;
var
lParams: TraParamList;
liPageNo: Integer;
begin

if Assigned(FOnPageChange) then FOnPageChange(Self);

liPageNo := CurrentPage.AbsolutePageNo;
lParams := TraParamList.Create;
lParams.AddParam('PageNo', daInteger, nil, '', False, False);
lParams.CreateValuePointer(0, liPageNo);

FWalkieTalkie.SendEventNotify(FWalkieTalkie, ciViewerPageChange, lParams);
end; {procedure, DoOnPageChange}

The lParams object and everything it owns is not freed. I have modified the
code in the following way and the leak has gone.

procedure TppViewer.DoOnPageChange;
var
lParams: TraParamList;
liPageNo: Integer;
begin

if Assigned(FOnPageChange) then FOnPageChange(Self);

liPageNo := CurrentPage.AbsolutePageNo;
lParams := TraParamList.Create;
try
lParams.AddParam('PageNo', daInteger, nil, '', False, False);
lParams.CreateValuePointer(0, liPageNo);

FWalkieTalkie.SendEventNotify(FWalkieTalkie, ciViewerPageChange,
lParams);
finally
FreeAndNil(lParams);
end;
end; {procedure, DoOnPageChange}

Can you please confirm that this fix is correct and lParams shouldn't be
destroyed somewhere inside of SendEventNotify?

Comments

This discussion has been closed.