First of all, I would like to thank the people who read the questions.
While implementing the pad server with delphi(tokyo) version, there is a memory leak in the process of creating multiple api and performance testing, and the server died, so I am checking the memory stick when I tested it with only one api. I don't know what went wrong. The photo shows the result of a memory leak as ReportMemoryLeaksOnShutdown:=true The left side is the result of one api and the right side is requested 1000 times with jmeter.
The api configuration and invocation are as follows. Part of Main.pas if (FN = 'getHosPet')then begin DM := TDM.Create(nil); try Ctxt.OutContent := StringToUTF8(DM.getHosPet(UTF8DecodeToUnicodeString(Ctxt.InContent),FN).ToString); Ctxt.OutContentType := JSON_CONTENT_TYPE; result := 200; finally freeAndNil(DM); end; end
The DM is TDM = class (TData Module). In the DM file, getHosPet is
function getHosPet (context: string;FN: String):TJSONObject; defined as this.
result.AddPair('code',TJSONNumber.Create(200)); result.AddPair('cmd' ,FN); result.AddPair('msg' ,objFind1); where objFind1 is the variable of the TJSONObject type. Even if you call the function of the DM in main.pas to get the value back, and set the free and nil values, the same result will occur if you search for data for a week to see if the TJSONObject or TJSONarrays received as a result are free. Also, even if DM.pas uses try finally to create objects with nil and free them, the value does not exceed the value properly or there is an access biasing error.
If there's anyone who knows about this, please give me some advice <
delphi memory jsonobject
You should free all the objects in the original TList.
If there are 5 TJSONObject objects in the TList, you have to free them 5 times for each object.
Use System.Generics.Collections.TobjectList instead of TList.
© 2024 OneMinuteCode. All rights reserved.