Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Problem StringToJString!! Memory not released!



Permlink Replies: 6 - Last Post: Apr 17, 2016 7:06 AM Last Post By: soippv ershike
soippv ershike

Posts: 4
Registered: 12/17/15
Problem StringToJString!! Memory not released!
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 9:37 AM
Hi!
I found a big problem.
Memory is not released when using StringToJString.
This Example:

function ImportToBaseAndroidIn:boolean;
var
ii:integer;
begin
Result:=false;
try
ii:=0;
while (ii<100000) do
begin
try
ii:=ii+1;
log.d('Number='+inttostr(ii));
StringToJString('TEST'); //CRASH AFTER~ 51200
except
end;
Result:=true;
end;
except
end;
end;

Crash With Error:
JNI ERROR (app bug): global reference table overflow (max=51200)

I also tried to assign Js: JString; Js: = StringToJString ( '..'); Js._Release;
but no effect! Whats wrong with StringToJString?
How free memory after StringToJString?

Rad Studio version: Embarcadero® RAD Studio 10 Seattle Version 23.0.20618.2753 ;

Edited by: soippv ershike on Apr 15, 2016 9:37 AM

Edited by: soippv ershike on Apr 15, 2016 11:31 AM

Edited by: soippv ershike on Apr 15, 2016 11:51 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Problem StringToJString!! Memory not released! [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 11:11 AM   in response to: soippv ershike in response to: soippv ershike
soippv wrote:

I found a big problem.

In which version of Delphi exactly?

Memory is not released when using StringToJString.

Are you absolutely sure about that? Firemonkey requires a lot of JString<->UnicodeString
conversions when dealing with the Android API, so I highly doubt that such
conversions would be leaking memory and nobody noticed before, unless this
is a new bug recently introduced. It is very common to use StringToJString()
to perform conversions inline in function parameters, for instance.

I also tried to assign

Js: String;
Js: = StringToJString ( '..');
Js._Release;

That should not even compile, since StringToJString() returns a JString,
not a String.

Whats wrong with StringToJString?

You tell us. Have you tried debugging your Android app and step into the
RTL source code to see what StringToJString() is actually doing?

--
Remy Lebeau (TeamB)
soippv ershike

Posts: 4
Registered: 12/17/15
Re: Problem StringToJString!! Memory not released! [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 11:36 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
In which version of Delphi exactly?

Rad Studio version: Embarcadero® RAD Studio 10 Seattle Version 23.0.20618.2753 ;

Memory is not released when using StringToJString.

Are you absolutely sure about that? Firemonkey requires a lot of JString<->UnicodeString
conversions when dealing with the Android API, so I highly doubt that such
conversions would be leaking memory and nobody noticed before, unless this
is a new bug recently introduced. It is very common to use StringToJString()
to perform conversions inline in function parameters, for instance.

I myself was very surprised that this function is a memory leak, because it is these features very often used in almost all of the examples, but nowhere else I could not find information about the memory leak.

I also tried to assign

Js: String;
Js: = StringToJString ( '..');
Js._Release;

That should not even compile, since StringToJString() returns a JString,
not a String.

Sorry, i mistake, i tried:

Js: JString;
Js: = StringToJString ( '..');
Js._Release;

Whats wrong with StringToJString?

You tell us. Have you tried debugging your Android app and step into the
RTL source code to see what StringToJString() is actually doing?

Inside StringToJString () i found function DeleteLocalRef, its should release memory, but actually the memory is not freed!!!

Edited by: soippv ershike on Apr 15, 2016 11:36 AM

Edited by: soippv ershike on Apr 15, 2016 11:38 AM

Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Problem StringToJString!! Memory not released! [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 11:47 AM   in response to: soippv ershike in response to: soippv ershike
Am 15.04.2016 um 20:38 schrieb soippv ershike:
In which version of Delphi exactly?

Rad Studio version: Embarcadero® RAD Studio 10 Seattle Version 23.0.20618.2753 ;

Memory is not released when using StringToJString.

Are you absolutely sure about that? Firemonkey requires a lot of JString<->UnicodeString
conversions when dealing with the Android API, so I highly doubt that such
conversions would be leaking memory and nobody noticed before, unless this
is a new bug recently introduced. It is very common to use StringToJString()
to perform conversions inline in function parameters, for instance.

I myself was very surprised that this function is a memory leak, because it is these features very often used in almost all of the examples, but nowhere else I could not find information about the memory leak.

I also tried to assign

Js: String;
Js: = StringToJString ( '..');
Js._Release;

That should not even compile, since StringToJString() returns a JString,
not a String.

Sorry, i mistake, i tried:

Js: JString;
Js: = StringToJString ( '..');
Js._Release;

Whats wrong with StringToJString?

You tell us. Have you tried debugging your Android app and step into the
RTL source code to see what StringToJString() is actually doing?

Inside StringToJString () i found function DeleteLocalRef, its should release memory, but actually the memory is not freed!!!

Edited by: soippv ershike on Apr 15, 2016 11:36 AM

Edited by: soippv ershike on Apr 15, 2016 11:38 AM


Hello,

how do you find out that memory is leaked?
On Android ReportMemoryLeaksOnShutdown := true doesn't work afaik.

There is this library wehich might provide leak checking:
https://bitbucket.org/shadow_cs/delphi-leakcheck/

Greetings

Markus
soippv ershike

Posts: 4
Registered: 12/17/15
Re: Problem StringToJString!! Memory not released! [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 15, 2016 12:00 PM   in response to: Markus Humm in response to: Markus Humm

how do you find out that memory is leaked?

I realized that the memory is not released, because the application crashes, and I see the logcat information:
JNI ERROR (app bug): global reference table overflow (max=51200)

51200 is just enough to execute this code: StringToJString('TEST');
If i comment this code - no errors!

procedure Test;
var
ii:integer;
begin
ii:=0;
while (ii<100000) do
begin
ii:=ii+1;
StringToJString('TEST'); //CRASH AFTER~ 51200 //if comment this function all work good.
end;
end;
//CRASH AFTER~ 51200


Try run this code and you will see it!!!

Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: Problem StringToJString!! Memory not released! [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 16, 2016 7:30 AM   in response to: soippv ershike in response to: soippv ershike
Am 15.04.2016 um 20:51 schrieb soippv ershike:
Hi!
I found a big problem.
Memory is not released when using StringToJString.

[snip example]

Please report this to quality.embarcadero,com asap!
And plkease tell us the report number and don't forgett to post your
example there.

Greetings

Markus
soippv ershike

Posts: 4
Registered: 12/17/15
Re: Problem StringToJString!! Memory not released! [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 17, 2016 7:06 AM   in response to: Markus Humm in response to: Markus Humm
Please report this to quality.embarcadero,com asap!
And plkease tell us the report number and don't forgett to post your
example there.

Greetings

My bug report:
https://quality.embarcadero.com/browse/RSP-14187
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02