[英]delphi XE6 TIdHTTP.Get (Indy 10) memory consuption
I have this function 我有这个功能
function doHTTPRequest(const AUrl: String): String;
// ------------------------------------------------------------------------
// return the response for a http request
var
aIdHTTP : TIdHTTP;
begin
Result := '';
aIdHTTP := TIdHTTP.Create(nil);
try
aIdHTTP.HandleRedirects := true;
aIdHTTP.RedirectMaximum := 5;
aIdHTTP.ConnectTimeout := 5000;
aIdHTTP.ReadTimeout := 10000;
Result := aIdHTTP.Get(aUrl);
aIdHTTP.Disconnect(false);
if Assigned(aIdHTTP.IOHandler) then
aIdHTTP.IOHandler.InputBuffer.Clear;
finally
if Assigned(aIdHTTP) then FreeAndNil(aIdHTTP);
end;
end;
Every time I call this function, the process in "task manager" increase private working set memory of 200 Byte (more or less). 每次我调用此函数时,“任务管理器”中的进程都会将专用工作集内存增加200字节(或多或少)。
where am I wrong? 我哪里错了?
I already use FastMM and AQTime but no memory leak have been found 我已经使用FastMM和AQTime,但是没有发现内存泄漏
this is an example of what i can see in task manager, from the begin
to end
the memory is increased by 200 Byte and it is never released... 这是我可以在任务管理器中看到,从一个例子
begin
到end
的内存增加到了200字节,并且从未发布...
doHTTPRequest
begin = 3.480 KB
end = 3.652 KB
----------------
diff. 184 Byte
doHTTPRequest
return value is html string (about 20 KB) doHTTPRequest
返回值是html字符串(约20 KB)
doHTTPRequest
is called by TIdHttpServer
like this: doHTTPRequest
调用TIdHttpServer
如下所示:
procedure TServer.CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
AResponseInfo.ContentText := doHTTPRequest('http://example.com/foo.html');
end
First, there is no need to call Disconnect()
or InputBuffer.Clear()
if you are just going to free the TIdHTTP
object immediately afterwards. 首先,如果您随后要立即释放
TIdHTTP
对象,则无需调用Disconnect()
或InputBuffer.Clear()
。 The destructor will close and free the socket for you if it is still connected. 如果析构函数仍处于连接状态,它将为您关闭并释放该套接字。
Second, TIdHTTP.Get()
does allocate memory internally when downloading content, but it also frees any memory it allocates. 其次,
TIdHTTP.Get()
在下载内容时不会在内部分配内存,但也会释放它分配的所有内存。 In your example, Get()
is returning a final String
representation of whatever content was downloaded. 在您的示例中,
Get()
返回所下载内容的最终String
表示形式。 You have to keep in mind that Delphi's memory manager ( FastMM by default) DOES NOT return freed memory back to the OS, the memory is cached for later re-use. 您必须记住,Delphi的内存管理器(默认情况下为FastMM ) 不会将释放的内存返回给操作系统,而是将内存缓存起来供以后重用。 That is what Task Manager is showing you.
这就是任务管理器向您显示的内容。 Task Manager only knows about the memory that your process has allocated from the OS, but it does not know how your process is actually using that memory.
任务管理器仅知道您的进程已从OS分配的内存,但不知道您的进程实际上是如何使用该内存的。 You cannot use Task Manager to diagnose memory leaks.
您不能使用任务管理器来诊断内存泄漏。 You have to use FastMM's own leak tracking features instead, since only it knows which memory is actually leaked or not.
您必须使用FastMM自己的泄漏跟踪功能,因为只有它知道实际泄漏的内存或没有泄漏的内存。 You can enable the global
ReportMemoryLeaksOnShutdown
variable in the System
unit, but the default installation of FastMM has minimal leak reporting enabled. 您可以在“
System
单元中启用全局ReportMemoryLeaksOnShutdown
变量,但是FastMM的默认安装启用了最少的泄漏报告。 For more detailed reporting, install the full version of FastMM into your project and configure it as needed. 有关更详细的报告,请在您的项目中安装FastMM的完整版本并根据需要进行配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.