TROHttpApiResult Question


I’ve httpApi function server and get out of memory issue when callling many times say 2000 times. I want to ask for the TROHttpApiResult Create and Free Handling:

Like Below Function:

I used the TROHttpApiResult.Create and stream the result to client side. How to free the binary object? As I tried , the result I get at client is nil.

If the Binary object, no need to free , can you advise why I get the out of memory?

function TAllTableService.getuser(const ENTITY_ID_PK, USER_ID_PK: UnicodeString): Binary;
  srcData: IDADataset;
  Result := TROHttpApiResult.Create(HTTP_200_code, id_ContentType_application_json_charset_utf8,'',false);


      //wb.NewBinaryExpression(wb.NewField('', 'USER_ENTITY_ID_PK'), wb.NewConstant(ENTITY_ID_PK), dboEqual),
      wb.NewBinaryExpression(wb.NewField('', 'USER_ID_PK'), wb.NewConstant(USER_ID_PK), dboEqual)

  srcData := AllTableDASchema.NewDataset(Connection,'USER_TBL',[],wb.Xml);
    sjoson.WriteDataset(srcData, [ woRows], -1);

  srcData := Nil;



Your method looks ok.
Result (i.e. Binary) shouldn’t be freed manually.
what service type you are using? CodeFirst- or RODL-based ?

It is codeFirst Server. Delphi 10.4.1, RO:

it is 32 bit server.

Please advise


I can’t reproduce any memory leaks with simple code like

function TNewProjectService.NewMethod: Binary;
  Result := TROHttpApiResult.Create(HTTP_200_code, id_ContentType_application_json_charset_utf8,'',false);
end; (110.2 KB)
I’ve used

curl -v -X POST "http://localhost:8099/api/test_post" -H  "accept: application/json" -o $$$.$$$

Can you test for memory leaks with FastMM4/FastMM5, pls?

1 Like

Thanks I wil test and get you reply. As I have a login first then then call the above login function.

I will test and check what case.


I used fastMM4 to check the project , it did not find any memory leakage.

I running a heavy testing on a batch to create a 400 thread to call this following function.

→ Login User ( DA operation to check password)
→ GetUser( DA operation to get user info)

If compile in 32 bit server , running this test I get out of memory error.
The exact error is below:
Error reading AllTableDASchema.Datasets: Out of memory
Error reading AllTableDASchema.Datasets: Error reading TDAServerDataset.Fields: Out of memory

If I need test a heavy loading, how to check why invoke this out of memory.
→ I already set the DB connection pool to 400 in Connection Manager.
If I need concurrent session around 400, what parameter do I need to take care?



You have 32bit server and 400 simultaneous requests so each request can consume only 2048 mb / 400 = ~5mb

also you have

Looks like, your task requires 64-bit server because peak memory consumption is great that 5mb per request.

Under peak memory consumption I mean 400 datasets and 400 TROHttpApiResult that contain a content of dataset in json format.
Also pay attention, that the server copies method’s result to response stream so available memory will be smaller, i.e. ~ 2,5 mb. This is in ideal conditions.
In real life, delphi memory manager also consumes some memory …

Yes, I tested and changed 64bit it is working.

for high loading server of httpAPI server, what kind of parameter I need take care?

Any Advise?


in your scenario you should try to decrease usage of memory for each request.
what I can recommend:

  • if you use TDASchema in read-only mode - try to move it to server datamodule. in this case you will decrease usage of memory required for each request and get some performance.
  • you may play with class factories. in your case you may change it to Pooled Class Factory . also you get some performance but usage of memory also will be increased because it should keep service instance in memory.