@@ -24,12 +24,16 @@ TGarbageList = class(TSimbaBaseClass)
24
24
FItems: TList;
25
25
26
26
procedure NotifyUnfreed ; override;
27
+
28
+ function GetCount : Integer;
27
29
public
30
+ constructor Create; reintroduce;
31
+ destructor Destroy; override;
32
+
28
33
procedure Add (Item: TJSONData);
29
34
procedure Del (Item: TJSONData);
30
35
31
- constructor Create; reintroduce;
32
- destructor Destroy; override;
36
+ property Count: Integer read GetCount;
33
37
end ;
34
38
35
39
TSimbaJSONParser = class (TBaseJSONReader)
@@ -60,6 +64,7 @@ TSimbaJSONParser = class(TBaseJSONReader)
60
64
procedure EndObject ; override;
61
65
public
62
66
constructor Create(Stream: TStream; FreeStream: Boolean); reintroduce;
67
+ destructor Destroy; override;
63
68
64
69
function Parse : TJSONData;
65
70
@@ -322,6 +327,14 @@ destructor TSimbaJSONInteger.Destroy;
322
327
inherited Destroy;
323
328
end ;
324
329
330
+ function TGarbageList.GetCount : Integer;
331
+ begin
332
+ if (FItems <> nil ) then
333
+ Result := FItems.Count
334
+ else
335
+ Result := 0 ;
336
+ end ;
337
+
325
338
procedure TGarbageList.NotifyUnfreed ;
326
339
327
340
function Dump (Item: TJSONData): String;
@@ -370,7 +383,8 @@ constructor TGarbageList.Create;
370
383
371
384
destructor TGarbageList.Destroy;
372
385
begin
373
- FItems.Free();
386
+ if (FItems <> nil ) then
387
+ FreeAndNil(FItems);
374
388
inherited Destroy();
375
389
end ;
376
390
@@ -519,10 +533,19 @@ class function TSimbaJSONParser.NewObject: TJSONObject;
519
533
constructor TSimbaJSONParser.Create(Stream: TStream; FreeStream: Boolean);
520
534
begin
521
535
inherited Create(Stream, DefaultOptions);
536
+
522
537
FGarbage := TGarbageList.Create();
523
538
if FreeStream then
524
539
Stream.Free();
525
540
end ;
526
541
542
+ destructor TSimbaJSONParser.Destroy;
543
+ begin
544
+ if (FGarbage.Count = 0 ) then
545
+ FreeAndNil(FGarbage);
546
+
547
+ inherited Destroy();
548
+ end ;
549
+
527
550
end .
528
551
0 commit comments