#1 2023-02-26 07:55:06

suoke
Member
Registered: 2023-02-09
Posts: 8
Website

Suggest adding aReplaceAndFreeOldObject for AddObject

When Member data is managed externally,like

var
  SynMustacheCache: TSynMustacheCache = nil;

SynMustacheCache's data update,will Trigger exception when memory release.
so:
TRawUtf8List.AddObject  Suggest adding aReplaceAndFreeOldObject.

    function AddObject(const aText: RawUtf8; aObject: TObject;
      aRaiseExceptionIfExisting: boolean = false;
      aFreeAndReturnExistingObject: PPointer = nil;
      aReplaceExistingObject: boolean = false;
      aReplaceAndFreeOldObject: boolean = true): PtrInt;

add aReplaceAndFreeOldObject: boolean
and
update here

        if aReplaceExistingObject then
        begin
          if Obj = nil then
            raise ESynException.CreateUtf8
              ('%.AddOrReplaceObject with no object at [%]', [self, aText]);
          if aReplaceAndFreeOldObject then //add here
            FreeAndNil(fObjects[result]);
          fObjects[result] := aObject;
        end
        else
          result := -1;
        exit;

when we need update ,can set aReplaceAndFreeOldObject:=false;

Last edited by suoke (2023-02-26 07:56:07)

Offline

Board footer

Powered by FluxBB