Memory handling of PODO

Hi.
I have totally forgotten somehing, since this cause leak. According to what I have read /remember serialized fields from result are freed automatically
My objects

  TChangeResult = class
  public
    table: string;
    Identifier: string;
    action: string;
    fieldsvalues: tObjectlist<tchangetext>;
    texts: tObjectlist<tchangetext>;
  end;

  TChangeResults = class
  private
    Flastkey: Integer;
    Fresults: TObjectlist<TChangeResult>;
  public
    property lastkey: integer read FLastKey write FLastKey;
    property results:  TObjectlist<TChangeResult> read FResults Write FResults;
  end;

Service Interface

    [ httpget, AuthorizeScopes( 'hidden' ) ]
    function getchanges( fromId: integer ): TChangeResults;

my servicemethod implementation (stripped to minimum)

begin
  Result := tchangeresults.Create;
  result.results := TObjectList<TChangeResult>.create(true);
  result.results.Add(TChangeResult.Create);
  EXIT; //

It leaks

41 - 56 bytes: TChangeResult x 1
89 - 104 bytes: TObjectList<skjserviceinterfaces.TChangeResult> x 1

output is serialized as expected

{
    "$id": 1,
    "@xdata.type": "skjserviceinterfaces.TChangeResults",
    "lastkey": 0,
    "results": [
        {
            "$id": 2,
            "@xdata.type": "skjserviceinterfaces.TChangeResult",
            "table": "",
            "Identifier": "",
            "action": "",
            "fieldsvalues": [],
            "texts": []
        }
    ]
}

Lists are exceptions (mostly due to legacy reasons). Your TChangeResults class has to destroy the Fresults field.

1 Like

I was confused at first. Since while destroying list I "automatically" tried to destroy elements inside list.
But then I realized it has similar logic as Aurelius, actual objects are destroyed
but lists are not.

1 Like

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