Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

after a stream was passed to CommandGet, when can it be freed?

with indy TIdHTTPServer, on the even of OnCommandGet, there is a possiblity to pass to AResponseInfo.ContentStream a stream with the data. which is fine. when can i release that stream? assuming the server can get multi requests, and any request could be handled at given time, and one stream can finish arbitrary to the other.

where could the stream be freed?

code example:

var
  StreamsToFree : TList;

//assume StreamsToFree := TList.create; properly 

procedure TObject.IdHttpServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
stream : TFileStream;
begin
  stream := TFileSTream.create('file.name');
  AResponseInfo.ContentStream := stream;
  AResponseInfo.ResponseNo := 200;
  StreamsToFree.Add(generateReceiptXML);  
end;

When can the stream be freed? on what even, and how do we know the IdHttpServer , finished its transfer?

like image 669
none Avatar asked Nov 15 '12 14:11

none


1 Answers

When you assign it to the ContentStream property, Indy becomes the owner of your stream and will free it when it's no longer needed.

Edit: Assuming you leave FreeContentStream property set to True (which is the default).

like image 116
Ondrej Kelle Avatar answered Oct 28 '22 00:10

Ondrej Kelle