Thanks Barbara.  I downloaded the rpgjnilib save file and I will try to get that uploaded so that I can use the service program.
Dean
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Barbara Morris
Sent: Thursday, September 20, 2012 7:03 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Calling Java from RPG take 2
On 2012/9/20 2:45 PM, Dean Eshleman wrote:
...
Do I need to worry about garbage collection if the process is called
multiple times within a job or is that handled for me?  From what I
understand, a new string object would be created each time the
program is called.  Should I set on LR each time it is called or
doesn't that make any difference other than from a performance
standpoint?
Yes, you do need to worry about garbage collection - nothing is handled 
for you. Setting on LR will have no effect at all on garbage collection. 
RPG never frees any objects other than the ones it creates itself to 
call the Java methods, so any objects that Java can't free during 
garbage-collection will remain until your job ends.
It's not just objects that you explicitly create that you have to worry 
about. It's any _references_ to objects. You don't actually deal with 
the objects themselves in your RPG programs; you deal with object 
references, similar in concept to pointers. When Java has passed you an 
object reference, even to an object that already existed, it remembers 
that you have that reference, and it will never free that object, even 
after all other Java processing was done with it.
So in your code, you explicitly create one String object with the 
makeString call, and you also get an object reference to the returned 
String object.
But it's pretty easy to handle once you get the JNI wrapper service 
program set up (you could use the one from the Cafe, and I think Scott 
Klement makes one available). Call beginObjGroup() at the beginning of 
where you will be creating objects that you won't need later, and then 
call endObjGroup() to tell Java that all the objects created the 
beginObjGroup() are now available for garbage collection.
As an Amazon Associate we earn from qualifying purchases.