#1 Re: mORMot 1 » how to free jo:Variant; TDocVariant.New(jo);; » 2021-10-31 15:34:18

hello ab,

Whatapp can't be used in CN. I don't know the rules of French BBS ,Sorry.

Next time I paste only the key code

My problem is solved

Use tdocvariant. Newjson (d_result);

No memory leaks.


thank you

#2 Re: mORMot 1 » how to free jo:Variant; TDocVariant.New(jo);; » 2021-10-30 00:53:53

if not free.
However, there is a memory leak.

How to deal with the memory leak?

#3 mORMot 1 » how to free jo:Variant; TDocVariant.New(jo);; » 2021-10-29 17:05:03

China Lee
Replies: 5

hi,every body.
how to  free   jo:Variant;  TDocVariant.New(jo);  jo.add(_Json('{"A":"11"}'));    Ctxt.OutContent :=   VariantSaveJson(_Obj(['code','1','msg','请求成功,Prc_WeiXin_DataList_Cust','data',+jo]));
i am try to Freeandnil(Jo),but error.Cause memory leak。
like this "13 - 20 bytes: AnsiString x 2"
I found that "_Json" caused the error. How can I fix this problem
who knows?
thank you

------------------------------------------
this is all code

--------------------------
function THttpServer.Prc_WeiXin_DataList_Cust(Ctxt: THttpServerRequest;
  aInHeaderSL: TRawUTF8List; const aRemoteIP: RawUTF8): cardinal;
var
  doc: TDocVariantData;
  expanded: Integer;
iRequestType, iRequestCode, vUserCode, dDate, PageIndex, PageSize, vExpression,D_URL: string;
  D_CountMax,D_PageMax,D_JsonData,D_PageInfo:string;
  aParam:SockString;
  aParameters: PUTF8Char;
  aName, aValue,D_Result: RawUTF8;
  jo:Variant;
begin
try
try
Ctxt.OutContentType := 'application/json';
    TDocVariant.New(jo);;
with DB(DefaultDB).CreateSpSMQuery() do
  begin
    with  Spquery do
    begin
      StoredProcName := 'Prc_WeiXin_DataList_Cust';
      PrepareSQL;
      ParamByName ('iRequestType').AsString :='3'; //不走条码为0
      ParamByName ('iRequestCode').AsString :='1'; //samp_sn
      ParamByName ('vUserCode').AsString := 'admin';
      ParamByName ('dDate').AsString := '2021-01-01'; //不是急查
      ParamByName ('iPageIndex').AsString :=  '1'; //inst_code
      ParamByName ('iPageSize').AsString := '2'; //inst_code
      ParamByName ('vExpression').AsString :=  '1=1'; //inst_code

      Execute;
        D_CountMax :=  ParamByName('iCountRows').AsString ;
          D_PageMax :=  ParamByName('iCountPage').AsString ;
     D_PageInfo := '"CountMax":"'+D_CountMax+'","PageMax":"'+D_PageMax+'",';
        D_Pageinfo := D_PageInfo + '"PageIndex":"'+ '1'+'","PageSize":"'+'2'+'"';
       if RecordCount >= 1 then
      begin
               if (D_CountMax = '0') and (D_PageMax = '0') then
        begin
          D_Result := '"data":[]';
        end
        else
        begin
          D_Result := '"data":'+ TDBDatasetToJson.DataSetToRawUTF8Json(SpQuery,true);
           //D_Result := '"data":'+DataSetToJSON(SpQuery); //MMT自带的
        end;
        D_Result :='{' + D_pageinfo +','+ D_Result + '}';
          Result := STATUS_SUCCESS;
            jo.add(_json(D_Result));

        Ctxt.OutContent :=   VariantSaveJson(_Obj(['code','1','msg','请求成功,Prc_WeiXin_DataList_Cust','data',+jo]));
      end
      else if RecordCount < 1 then
      begin
        Result := STATUS_SUCCESS;
        D_Result := '{' + D_pageinfo +',"data":[]}';
           jo.add(_json(D_Result));
          Ctxt.OutContent :=  VariantSaveJson(_Obj(['code','0','msg','请求失败,Prc_WeiXin_DataList_Cust','data',+jo]));
      end;

    end;
end;
  except on E: Exception do
  begin
  Ctxt.OutContent :=  VariantSaveJson(_Obj(['code','0','msg','请求失败,Prc_WeiXin_DataList_Cust','data',e.Message]));
   Set_Log('方法:'+Ctxt.Method+'  URL:'+Ctxt.URL+' [ERR出参] ',Ctxt.OutContent,1,form1.mmo1,info);
  end;
end;
finally
 
end;
end;

Board footer

Powered by FluxBB