FMX Listview memory leak adding bitmaps

  

Clicking on a button and loading around 1200 thumbnails from disk to a fmx listview on Windows 10. Plan to use on Windows, Android and maybe Apple platforms. Upon closing the app, Unexpected Memory Leak error occurs. I have tried many different iterations of the code but each results in the same error. Guidance on what I am doing wrong with freeing the bitmaps would be greatly appreciated.

I have tried using FreeAndNil for both thumbbit and tbit2 in many different places. I have also tried .DisposeOf, .Free and :=nil.

ListView.BeginUpdate;
for i:=0 to ListView.Items.Count -1 do
begin
try
ThumbBit := TBitmap.Create(0,0);
tbit2 := TBitmap.Create(0,0);
aitem := ListView.items.AppearanceItem[i];
draw2 := ListView.Items.Item[i].View.FindDrawable(‘thumbpath’);
thumbpath:= draw2.Data.ToString;
LThumb := (AItem.Objects.FindDrawable(‘imagethumb’) as TListItemImage);
try
ThumbBit.LoadThumbnailFromFile(thumbpath, 60, 90, true);
Tbit2.Assign(ThumbBit);
LThumb.Bitmap:=Tbit2;
finally
FreeAndNil(tbit2);
end;
finally
FreeAndNil(ThumbBit);
end;
end;
ListView.EndUpdate;

Application works fine but results in the error ‘Unexpected Memory Leak error occurs’ when closing the application on windows. I have not tested this on other platforms.

Error message:

Comments are closed.