function TJSONObject.toString(indentFactor, indent: integer): string;
This function has a line: _keys := keys(); The _keys not free until the function exit.
Please add a try .. finally _keys.Free end; for this function.
The line: key := x.nextValue().toString(); will cause a memory leak, too.
Please write in this way:
with x.nextValue() do
begin
key...