开发者

Is not freeing TMemoryStream causing a memory leak?

I am using TWebModule with Apache. I am having problems with a memory leak. In the code below is not freeing the ImageStream a memory leak? If I do free it I get an access violation.

procedure TWebModule1.WebModule1WebActionItem8Action(Sender: TObject;
    Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
  var
    RecNo: Integer;
    ImageStream: TmemoryStream;
  begin
    RecNo := StrToInt(Request.QueryFields.Values['RecNo']);
    Master.MoveBy(RecNo - Master.RecNo); // go to right record
    ImageStream := TMemoryStream.Create;
    with TGraphicField.Create(Master) do
    try
      FieldName := 'Graphic';
      SaveToStream(ImageStream)
    finally
      Free
    end;
    ImageStream.Position := 0; // reset ImageStream
    Response.ContentType := 'image/jpg';
    Response.ContentStream := ImageStream;
开发者_运维知识库    Response.SendResponse
  end;


From here:

If you use the ContentStream property, do not free the stream yourself. The Web response object automatically frees it for you.

Having said that, why involve ImageStream at all? Why not just use:

Response.ContentStream := TMemoryStream.Create

and save the image to that stream directly?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜