Title: Memory issue with DelphiDataSetToRtc Post by: jorgen on April 12, 2016, 12:48:18 PM I have this code:
class function TServer_Utils.JSONFromDataset(ADataset: TDataSet): String; var rtcDS: TRtcDataSet; AHugeString: TRtcHugeString; begin AHugeString := nil; rtcDS := TRtcDataSet.Create; try AHugeString := TRtcHugeString.Create; DelphiDataSetToRtc(ADataset, rtcDS); // This function is in the "rtcDB" unit rtcDS.to_JSON(AHugeString); Result := AHugeString.Get; finally // rtcDS.Clear; FreeAndNil(rtcDS); FreeAndNil(AHugeString); end; end; It is 800 rows in the dataset It uses 10 mb of memory, but only the first time it is used, Here is the memory use: 12 MB DelphiDataSetToRtc(ADataset, rtcDS); 18 MB rtcDS.to_JSON(AHugeString); 21 MB Result := AHugeString.Get; 23 MB FreeAndNil(rtcDS); 21 MB FreeAndNil(AHugeString); 21MB Shouldn't it be possible to do this without any memory leak? Jørgen Title: Re: Memory issue with DelphiDataSetToRtc Post by: D.Tkalcec (RTC) on April 12, 2016, 12:58:09 PM How are you checking your Application's Memory Usage?
Best Regards, Danijel Tkalcec Title: Re: Memory issue with DelphiDataSetToRtc Post by: D.Tkalcec (RTC) on April 12, 2016, 01:44:05 PM By the way (not directly related to your memory question) ... if you just want a JSON String from a TRtcValueObject instance (like TRtcDataSet), there is no need to manually declare, create and free a local TRtcHugeString variable. You can simply use the "toJSON" method (or "toJSONEx" - if you want a RtcByteArray instead of a String).
In other words, your code example (from above) would look like this: class function TServer_Utils.JSONFromDataset(ADataset: TDataSet): String; var rtcDS: TRtcDataSet; begin rtcDS := TRtcDataSet.Create; try DelphiDataSetToRtc(ADataset, rtcDS); // This function is in the "rtcDB" unit Result := rtcDS.toJSON; finally rtcDS.Free; end; end; Best Regards, Danijel Tkalcec Title: Re: Memory issue with DelphiDataSetToRtc Post by: D.Tkalcec (RTC) on April 13, 2016, 07:45:26 AM Check these DocWiKi Topics about Delphi Memory Management:
http://docwiki.embarcadero.com/RADStudio/XE8/en/Memory_Management http://docwiki.embarcadero.com/RADStudio/XE8/en/Monitoring_Memory_Usage http://docwiki.embarcadero.com/RADStudio/XE8/en/Configuring_the_Memory_Manager Best Regards, Danijel Tkalcec |