gpt4 book ai didi

delphi - 释放TMemoryStream不会导致内存泄漏吗?

转载 作者:行者123 更新时间:2023-12-03 15:53:28 24 4
gpt4 key购买 nike

我正在将 TWebModule 与 Apache 一起使用。我遇到内存泄漏问题。下面的代码中是否没有释放ImageStream内存泄漏?如果我释放它,我就会遇到访问冲突。

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;

最佳答案

来自here :

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

话虽如此,为什么还要涉及 ImageStream 呢?为什么不直接使用:

Response.ContentStream := TMemoryStream.Create

并将图像直接保存到该流中?

关于delphi - 释放TMemoryStream不会导致内存泄漏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3483831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com