@@ -24,12 +24,16 @@ TGarbageList = class(TSimbaBaseClass)
2424 FItems: TList;
2525
2626 procedure NotifyUnfreed ; override;
27+
28+ function GetCount : Integer;
2729 public
30+ constructor Create; reintroduce;
31+ destructor Destroy; override;
32+
2833 procedure Add (Item: TJSONData);
2934 procedure Del (Item: TJSONData);
3035
31- constructor Create; reintroduce;
32- destructor Destroy; override;
36+ property Count: Integer read GetCount;
3337 end ;
3438
3539 TSimbaJSONParser = class (TBaseJSONReader)
@@ -60,6 +64,7 @@ TSimbaJSONParser = class(TBaseJSONReader)
6064 procedure EndObject ; override;
6165 public
6266 constructor Create(Stream: TStream; FreeStream: Boolean); reintroduce;
67+ destructor Destroy; override;
6368
6469 function Parse : TJSONData;
6570
@@ -322,6 +327,14 @@ destructor TSimbaJSONInteger.Destroy;
322327 inherited Destroy;
323328end ;
324329
330+ function TGarbageList.GetCount : Integer;
331+ begin
332+ if (FItems <> nil ) then
333+ Result := FItems.Count
334+ else
335+ Result := 0 ;
336+ end ;
337+
325338procedure TGarbageList.NotifyUnfreed ;
326339
327340 function Dump (Item: TJSONData): String;
@@ -370,7 +383,8 @@ constructor TGarbageList.Create;
370383
371384destructor TGarbageList.Destroy;
372385begin
373- FItems.Free();
386+ if (FItems <> nil ) then
387+ FreeAndNil(FItems);
374388 inherited Destroy();
375389end ;
376390
@@ -519,10 +533,19 @@ class function TSimbaJSONParser.NewObject: TJSONObject;
519533constructor TSimbaJSONParser.Create(Stream: TStream; FreeStream: Boolean);
520534begin
521535 inherited Create(Stream, DefaultOptions);
536+
522537 FGarbage := TGarbageList.Create();
523538 if FreeStream then
524539 Stream.Free();
525540end ;
526541
542+ destructor TSimbaJSONParser.Destroy;
543+ begin
544+ if (FGarbage.Count = 0 ) then
545+ FreeAndNil(FGarbage);
546+
547+ inherited Destroy();
548+ end ;
549+
527550end .
528551
0 commit comments