1
I need to create a complex Json, with several objects, and each object will have items;
{
"Pedidos": [
    {
        "CodCad": "1286",
        "CodForPag": "15",
        "CodCndPag": "43",
        "CodUndAdm": "1",
        "DatEmi": "19/05/2021",
        "DatSol": "26/04/2021 21:42:00",
        "PesCnt": "GLADSON",
        "Tel": "0000000000",
        "Sta": "0",
        "Itens": [
            {
                "CodPro": "310",
                "CodUnd": "66",
                "Qtd": "10",
                "Vlr": "11",
                "Und": "UN",
                "Cmp": "0",
                "Lrg": "0",
                "M2m": "0",
                "Sta": "0",
                "VlrDsc": "0",
                "VlrTot": "110",
                "PrdSrv": "0",
                "NumRqc": "",
                "NumMapCol": "1",
                "EspExt": "60PVD",
                "QtdAtd": "0"
            },
            {
                "CodPro": "3251",
                "CodUnd": "66",
                "Qtd": "3",
                "Vlr": "15",
                "Und": "UN",
                "Cmp": "0",
                "Lrg": "0",
                "M2m": "0",
                "Sta": "0",
                "VlrDsc": "0",
                "VlrTot": "45",
                "PrdSrv": "0",
                "NumRqc": "",
                "NumMapCol": "1",
                "EspExt": "",
                "QtdAtd": "0"
            }
        ]
    },
    ...
    ...
]
}
I realize that when I create a Tjsonobjet and Tjsonarray, and I go Free in them generate me a violation.
JSon := TJsonObject.Create();
APedidos := TJsonArray.Create();
while not cdsMapOrd001.Eof do
begin
I need to use Freeandnil on all created objects ?
Thank you very much. Clarified. According to what you said I researched and found this topic : https://stackoverflow.com/questions/44584751/reportmemoryleaksonshutdown-not-working-in-delphi-10-2-tokyo and the answer speaks of Xe2.
– Gladson Reis
I didn’t understand the use of
ReportMemoryLeaksOnShutdown := TrueIt presents a screen with a lot of information, but nothing in detail. You would have some suggestion for studies ?– Gladson Reis
This screen that appears with A lot of information is telling you what was left in your application without being destroyed.
– Junior Moreira
Complementing Junior’s answer, I advise checking with if Assigned(vJsonResulted) then at the end of the object. Just like the other objects created and remove from memory with vJsonResult := nil; vJsonResulted.free. Because handling with JSON objects can give problem with "pointer error" when finishing Freeandnil().
– Jefferson Rudolf