alexdeww / dson Goto Github PK
View Code? Open in Web Editor NEWSimple Delphi JSON Serializer
Simple Delphi JSON Serializer
Hello,
When an Object is embedded into a record, a Memory Leak is generated.
unit Main;
{$I Defines}
interface
uses
Winapi.Windows, REST.JSON, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
uDSON;
type
TForm1 = class(TForm)
Memo1: TMemo;
ObjectBtn: TButton;
procedure ObjectBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TRecordObject=class
private
FP1 : Integer;
FP2 : TBytes;
FP3 : string;
FP4 : TDateTime;
published
property P1 : Integer read FP1 write FP1;
property P2 : TBytes read FP2 write FP2;
property P3 : string read FP3 write FP3;
property P4 : TDateTime read FP4 write FP4;
end;
TJsonRecord=
record
Dummy : string;
O : TRecordObject;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ObjectBtnClick(Sender: TObject);
var
O : TRecordObject;
JsonRecord : TJsonRecord;
sJson : string;
begin
O := TRecordObject.create;
O.P1 := 11;
O.P2 := [3,2,1];
O.P3 := 'String';
O.P4 := now;
//////////////////////////////
JsonRecord := default(TJsonRecord);
JsonRecord.Dummy := 'Dummy';
JsonRecord.O := O;
//////////////////////////////
sJson := TDSON.ToJson(JsonRecord);
Memo1.Lines.Add(sJson);
JsonRecord := TDSON.FromJson<TJsonRecord>(sJson);
sJson := TDSON.ToJson(JsonRecord);
Memo1.Lines.Add(sJson);
FreeAndNil(O);
end;
initialization
ReportMemoryLeaksOnShutdown := True;
finalization
end.
--------------------------------2021/1/4 16:43:53--------------------------------
A memory block has been leaked. The size is: 36
This block was allocated by thread 0x1220, and the stack trace (return addresses) at the time was:
00645E0F [uMemory.pas][uMemory][NewAllocMem][73]
0040708E [System.pas][System][@GetMem][4830]
00409FF3 [System.pas][System][@NewUnicodeString][25285]
0040A224 [System.pas][System][@UStrFromPWCharLen][25963]
0064F87B [System.JSON.pas][System.JSON][TJSONByteReader.FlushString][1542]
006525DF [System.JSON.pas][System.JSON][TJSONObject.ParseString][2804]
00651BCC [System.JSON.pas][System.JSON][TJSONObject.ParseValue][2544]
006519AA [System.JSON.pas][System.JSON][TJSONObject.ParsePair][2489]
006517C3 [System.JSON.pas][System.JSON][TJSONObject.Parse][2438]
0065190E [System.JSON.pas][System.JSON][TJSONObject.ParseObject][2468]
00651BEC [System.JSON.pas][System.JSON][TJSONObject.ParseValue][2558]
The block is currently used for an object of class: Unknown
The allocation number is: 1575
--------------------------------2021/1/4 16:43:53--------------------------------
A memory block has been leaked. The size is: 36
This block was allocated by thread 0x1220, and the stack trace (return addresses) at the time was:
00645E0F [uMemory.pas][uMemory][NewAllocMem][73]
004070FD [System.pas][System][@ReallocMem][5022]
0040708E [System.pas][System][@GetMem][4830]
0040801B [System.pas][System][TObject.NewInstance][17514]
004087EA [System.pas][System][@ClassCreate][18867]
00408100 [System.pas][System][TObject.Create][17573]
00467EDE [System.Rtti.pas][System.Rtti][PutArg][8024]
00467DB8 [System.Rtti.pas][System.Rtti][RawInvoke][7914]
004681BC [System.Rtti.pas][System.Rtti][Invoke][8136]
0045EF72 [System.Rtti.pas][System.Rtti][TRttiInstanceMethodEx.DispatchInvoke][6011]
004686E7 [System.Rtti.pas][System.Rtti][TRttiMethod.Invoke][9436]
The block is currently used for an object of class: Unknown
The allocation number is: 1893
--------------------------------2021/1/4 16:43:53--------------------------------
A memory block has been leaked. The size is: 20
This block was allocated by thread 0x1220, and the stack trace (return addresses) at the time was:
00645E0F [uMemory.pas][uMemory][NewAllocMem][73]
004070FD [System.pas][System][@ReallocMem][5022]
0040C51D [System.pas][System][DynArraySetLength][36046]
0040B367 [System.pas][System][@InitializeArray][32446]
00452139 [System.Rtti.pas][System.Rtti][MakeDynamic][2752]
0040B3A9 [System.pas][System][@FinalizeRecord][32627]
0045236E [System.Rtti.pas][System.Rtti][TValue.FromArray][2800]
0065B355 [uDSON.pas][uDSON][TDSONValueReader.readDynArrayValue][307]
0065BC22 [uDSON.pas][uDSON][TDSONValueReader.tryReadValueFromJson][443]
0065B9C1 [uDSON.pas][uDSON][TDSONValueReader.setObjValue][414]
0046034B [System.Rtti.pas][System.Rtti][TRttiInstanceProperty.GetName][6478]
The block is currently used for an object of class: Unknown
The allocation number is: 1916
--------------------------------2021/1/4 16:43:53--------------------------------
This application has leaked memory. The small block leaks are (excluding expected leaks registered by pointer):
13 - 20 bytes: Unknown x 1
21 - 36 bytes: Unknown x 2
Note: Memory leak detail is logged to a text file in the same folder as this application. To disable this memory leak check, undefine "EnableMemoryLeakReporting".
Best regards.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.