I got this procedure to load image async, the problem is when i free the lBitmap Object, if i free i got AV on top, but i need free it because the allocated memory.
How can i free lBitmap Object?
procedure LoadMyImage(AImage: TBitmap; AImageURL: string);
var
temp: TBitmap;
lBitmap: TBitmap;
begin
lBitmap := nil;
if FCachedImages.TryGetValue(AImageURL, lBitmap) and (lBitmap <> nil) then
begin
AImage.Assign(lBitmap);
end
else
begin
AsyncTask.Run(THttpAsyncTaskBitmap.Create(AImageURL),
procedure (ATask: IAsyncTask)
begin
TThread.Queue(nil,
procedure
begin
lBitmap := TBitmap.Create(0,0);
temp := FMX.Graphics.TBitmap.CreateFromStream((ATask as IHttpResponse).ResponseStream);
lBitmap.Assign(temp);
FCachedImages.AddOrSetValue(AImageURL, lBitmap );
AImage.Assign(temp);
temp.Free;
lBitmap.Free; //—> if i free the object i got AV on top
end);
end);
end;
end;