RTC Forums
November 24, 2024, 01:49:01 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Help
Login
Register
RTC Forums
>
Subscription
>
Support
>
Memory issue with DelphiDataSetToRtc
Pages: [
1
]
« previous
next »
Print
Author
Topic: Memory issue with DelphiDataSetToRtc (Read 4891 times)
jorgen
RTC Expired
Posts: 20
Memory issue with DelphiDataSetToRtc
«
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
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Memory issue with DelphiDataSetToRtc
«
Reply #1 on:
April 12, 2016, 12:58:09 PM »
How are you checking your Application's Memory Usage?
Best Regards,
Danijel Tkalcec
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Memory issue with DelphiDataSetToRtc
«
Reply #2 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
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Memory issue with DelphiDataSetToRtc
«
Reply #3 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
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Dashboard
-----------------------------
=> General
=> 3rd-Party
=> Quick Start
-----------------------------
Subscription
-----------------------------
=> Support
Loading...