Using Delphi 10.2 (Tokyo)
Below is the code for a full console application that displays an unexpected memory leak (TUTF8Encoding) when calling one URL and memory leak when calling another.
Comparing headers between two answers:
What a memory leak contains
Content-Type=application/json
One that contains no memory leak contains
Content-Type=application/json; charset=utf-8
Is this a mistake, or should I do something to prevent this?
program RESTMemLeakTest; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, IPPeerClient, REST.Client, REST.Types; var RESTClient1: TRESTClient; RESTRequest1: TRESTRequest; URL: string; begin ReportMemoryLeaksOnShutdown := True; URL := 'https://httpbin.org/post'; // memory leak //URL := 'https://jsonplaceholder.typicode.com/posts'; // no memory leak RESTClient1 := TRESTClient.Create(URL); RESTRequest1 := TRESTRequest.Create(nil); try try RESTRequest1.Client := RESTClient1; RESTRequest1.Method := rmPOST; RESTRequest1.Execute; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; finally RESTRequest1.Free; RESTClient1.Free; end; end.
Running the application with a URL that memory leak returns this:
An unexpected memory leak has occurred. Unexpected small leak block:
21 - 28 bytes: TUTF8Encoding x 1
Update . Setting the FallbackCharsetEncoding parameter to an empty string means to fix a memory leak. No known problems (yet) this is being done. I am going to open an error report with Embarcadero to find out what they are saying. Therefore, adding the line below before executing the query will prevent an unexpected memory error message.
RESTClient1.FallbackCharsetEncoding := '';
Update 2 : The RSP-17695 error report was sent on March 30, 2017.
Update 3 : August 8, 2017: bug resolved in version 10.2 of Tokyo Release 1