Delphi REST memory leak error

I'm currently looking for a way to avoid an explicit memory leak in the Mac implementation of the REST client. The code for generating a memory leak is as follows (XE8 Launch, Update 1):

program mac_REST_leak_test; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, REST.Client, REST.Types, IPPeerClient; var request : TRestRequest; ii, iMax : integer; begin iMax := 1; for ii := 0 to iMax do begin request := TRestRequest.Create(nil); // Fake Online REST API for Testing and Prototyping request.Client := TRestClient.Create('http://jsonplaceholder.typicode.com/'); request.Method := rmPOST; request.Execute(); request.Client.Free(); request.Free(); end; end. 

This is the smallest block of code that shows a leak. Essentially, I have a synchronization service that makes REST requests so often.

When I run this on Windows using MadExcept, no leaks were detected. Studying the current process in ProcessMonitor does not show an increase in memory usage.

When launched on a Mac, Activity Monitor shows that the memory allocated for the application continues to grow. In addition, when you start using tools, there are leaks associated with several URLs and HTTP classes on mac.

Does anyone know how to resolve this leak?

(As an aside, it would be very useful to know exactly where the leak occurs on the Mac, but the only Delphi classes listed are TMethodImplementationIntercept. I should assume that this is because Delphi doesn’t create the dSYM file for Mac. If anyone knows about it, that would be cool too!)

UPDATE By changing iMax from 1 to 10 and comparing FastMM4 output, it seems that the leak is in the Macapi.ObjectiveC.TConvObjID.XForm class. The output of 10 iterations contains another 9 leaks with this as a stack trace compared to the 1st iteration. I reported this to Embarcadero as an RSP-12242.

+5
source share
1 answer

Yes FastMM4 has OSX leak reporting support in the latest version of SVN. Unfortunately, "global" leaks from a simple empty Delphi FMX application make it difficult to parse the mem-log file. Several leaks were fixed in XE10, but some objects in the MacApi.ObjectiveC bridge still produce leaks. I reported that in a high-quality and high-quality portal (QC and QP). Therefore, it is difficult to use FastMM4 for leak detection.

Separate Delphi object leaks and ObjectiveC leaks that you can find with tools.

+2
source

Source: https://habr.com/ru/post/1232301/


All Articles