#1 2017-08-24 02:55:36

linbren
Member
Registered: 2017-08-11
Posts: 42

TDocVariant raise a memory leak exception.

function testMormetJson():string;
var
  jo: Variant;
  i: Int64;
  sTemp:string;
begin
  TDocVariant.New(jo);
  i := 0;
  while i < 10 do
  begin
    jo.Name := 'This is a Str' + IntToStr(i);
    jo.Age := i;
    jo.List := _JSon('[1,"Hello",5,{"name":"c5soft","age":50}]');
    sTemp:=sTemp+VariantSaveJSON(jo)+#13#10;
    inc(i);
  end;
  result:=sTemp;
end;
////////////////////////////
well , this code is from somewhere ...
there is a "new" , no "free" found.
I can not find a method of "free" from TDocVariant .


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

#2 2017-08-24 03:01:09

linbren
Member
Registered: 2017-08-11
Posts: 42

Re: TDocVariant raise a memory leak exception.

win7  64X
target 32
tokyo 10.2


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

#3 2017-08-24 03:02:23

linbren
Member
Registered: 2017-08-11
Posts: 42

Re: TDocVariant raise a memory leak exception.

FreeAndNil(jo)  doesn't work.


Windows 7 64bit. Delphi XE10.2 Professional.

Offline

#4 2017-08-24 07:26:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: TDocVariant raise a memory leak exception.

Your above code doesn't leak memory.

The value is the variant variable.
TDocVariant is a meta-class, used to define the document custom type defined in SynCommons.

A variant is a value-type, with scope-based automatic reference (just like string, but without reference counting).
So there is no free.

Online

Board footer

Powered by FluxBB