I have an app written in Delphi 11. I have used a TIdHttp client to receive a live stream from a camera. The data is received in the OnWork event.
My code looks something like this
procedure TStreamingThread.IdHttpLiveStreamWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
var
MemoryStream: TMemoryStream;
BytesToRead: NativeInt;
begin
MemoryStream := TMemoryStream.Create;
try
BytesToRead := IdHttpLiveStream.Response.ContentStream.Position - LastPosition;
//read from where we got up to last time to the end of the stream
IdHttpLiveStream.Response.ContentStream.Position := LastPosition;
MemoryStream.CopyFrom(IdHttpLiveStream.Response.ContentStream, BytesToRead);
//extract the jpg data from the stream and use it update the screen
//update LastPosition so that we are ready for the next time
LastPosition := LastPosition + BytesToRead;
finally
MemoryStream.Free;
end;
I use the extracted jpg data to update a TPicture and it is all working.
My question is regarding ContentStream. Isn't it going to keep increasing in size and eventually cause an out of memory error? Should I be resetting it and if so how?