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.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.