Hi,
I am trying to requst a web interface with a http post command.
Everything is going well and I get a response (xml string) from the interface .
But while executing this task up to 1.3 Gb RAM is being used.
If the request has been done, up to 600 Mb of memory ist still being used by the programm.
Can you support me with this issue?
Thanks.
It is my delphi code (RAD Studio 10.1 Berlin):
procedure Tfrmmain.btnrequestClick(Sender: TObject);
var
Response: TScHttpWebResponse;
ResponseStr: string;
buff: TBytes;
xml: String;
igspn: TScHttpWebRequest;
begin
try
xml:= ' ### original xml string ###';
igspn:= TScHttpWebRequest.Create(Application);
igspn.RequestUri:= '### original URL ###';
igspn.ContentType:= 'text/xml';
igspn.KeepAlive:= true;
igspn.Method:= rmPOST;
igspn.headers.Add('Authorization','Basic '+ TBase64Encoding.Base64.Encode('##username##+ ':' + '##password##'));
buff:= TEncoding.UTF8.GetBytes(xml);
igspn.ContentLength:= Length(buff);
igspn.WriteBuffer(buff);
igspn.SendChunked := false;
Response:= igspn.GetResponse;
memo1.Lines.Text:= Response.ReadAsString;
FreeAndNil(response);
except on e: Exception do begin
ShowMessage(e.Message);
end;
end;
end;
TScHttpWebRequest memory leak
-
- Devart Team
- Posts: 70
- Joined: Wed 02 Jun 2021 09:30
Re: TScHttpWebRequest memory leak
Hi!
Please note that when using the ReadAsString method in the way you described, the memory is allocated three times: once in the ReadAsString method itself, once as output result and one more time in Memo itself.
To solve the issue, in order to reduce the consumption of RAM, you can use the TScHttpWebResponse.ReadToStream method by specifying an object of the TFileStream class in the parameters, in which case the server response will be saved to disk and not to RAM.
Please note that when using the ReadAsString method in the way you described, the memory is allocated three times: once in the ReadAsString method itself, once as output result and one more time in Memo itself.
To solve the issue, in order to reduce the consumption of RAM, you can use the TScHttpWebResponse.ReadToStream method by specifying an object of the TFileStream class in the parameters, in which case the server response will be saved to disk and not to RAM.
Re: TScHttpWebRequest memory leak
Is this Problem solved?
I need to send a lot requests. If i call httpwebrequest.GetResponse the used memory go up. The Call httpwebresponse.free do not release the memory.
This is a problem, because i have to call up to 10000 requests.
I need to send a lot requests. If i call httpwebrequest.GetResponse the used memory go up. The Call httpwebresponse.free do not release the memory.
This is a problem, because i have to call up to 10000 requests.
Re: TScHttpWebRequest memory leak
Check if a memory leak occurs if you release the HttpWebRequest object, not just the HttpWebResponse.