TScHttpWebRequest memory leak

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
Posts: 1
Joined: Wed 16 Feb 2022 09:18

TScHttpWebRequest memory leak

Post by AliakseiY » Wed 16 Feb 2022 09:43

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?

It is my delphi code (RAD Studio 10.1 Berlin):

procedure Tfrmmain.btnrequestClick(Sender: TObject);
Response: TScHttpWebResponse;
ResponseStr: string;
buff: TBytes;
xml: String;
igspn: TScHttpWebRequest;
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.SendChunked := false;
Response:= igspn.GetResponse;
memo1.Lines.Text:= Response.ReadAsString;
except on e: Exception do begin

Devart Team
Posts: 70
Joined: Wed 02 Jun 2021 09:30

Re: TScHttpWebRequest memory leak

Post by YanishevskiyVI » Mon 21 Feb 2022 12:18


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.

Posts: 7
Joined: Mon 09 Jun 2008 12:58

Re: TScHttpWebRequest memory leak

Post by ualms » Tue 02 Aug 2022 07:59

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.

Devart Team
Posts: 2909
Joined: Mon 05 Mar 2007 16:32

Re: TScHttpWebRequest memory leak

Post by Dimon » Fri 05 Aug 2022 13:24

Check if a memory leak occurs if you release the HttpWebRequest object, not just the HttpWebResponse.

Post Reply