Memory Management of Classes acquired with RawInvoke

Continuing from this

Am I able to return a record from an endpoint - #3 by wlandgraf

When I am accepting the class from the endpoint

  procedure OnResult (Response : TXDataClientResponse);
  var
    lRes        : TJSObject;
    LPlan_Added : TPlan_Added;
  begin
    if Response.Succeeded
    then begin
         LRes := TJSObject (Response.Result);
         LPlan_Added := TPlan_Added(TObject(LRes));
         if Assigned (ACBSuccess)
         then ACBSuccess (LPlan_Added);
    end
    else OnFail (Response.Error_Msg);
  end;

Where TPlan_Added is a class. Its just occurred to me that I am not freeing it in the caller. Will it get freed automatically because of scope and reference counting, or do I need to free it?

You are in a Web Core application thus in a in-browser JavaScript app.

In JavaScript world, nothing needs to be destroyed. You can choose either call Free or not, it doesn't matter much.

The equivalent in Delphi would be using TXDataClient, and in that case, you also don't need to destroy objects returned by TXDataClient since it destroys its returned objects automatically, so your code is fine.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.