× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Barbara,

Thanks for the tip. You are right that it not intuitive to have to
clean up a reference to a String. I changed that code from
something that looked like the following because nested
calls were getting hard to follow.

     invElement = newElement(newString('invoice'));

In this case I am guessing that it holds the reference from
the invElement and will allow garbage collect for the string
when the element is released. If this is the case I will try to
use this notation.

Thanks,

David

>>> bmorris@ca.ibm.com 02/08/02 02:09PM >>>
>Date: Fri, 08 Feb 2002 05:11:02 -0700
>From: "David Morris" <David.Morris@plumcreek.com>
> ...
>      /free
> 1        wrkString = newString('invoice');
>          invElement = newElement(wrkString);
>          invDocument = newDocument(invElement);
> 2        wrkString = newString('/home/dmorris/simpleinvoice.xml');
>          invFileWriter = newFileWriter(wrkString);
>          XMLOutputter$output(invXMLOutputter: invDocument:
>             invFileWriter);
>      /end-free

David, this code has a problem that I imagine will turn out to
be a common problem.  It's similar to a memory leak (object leak)?

At the line I marked 1, you create a new string object.  Then you
get another new string object at line 2, losing the reference to
the first string object.  This would be fine in Java, since Java
understands lost object references.  But Java has no idea that
your RPG code lost the object reference, so it can never free that
object.  You should be calling freeLocalRef(wrkString) before
you get the second string.  There's an example of doing this in
the Programmer's Guide.

All those references should probably be freed before the procedure
returns.

(If this is a native method, called from Java, it's not so important.
In fact, with native methods, the opposite problem exists.  Java
assumes that all objects created during native methods can be freed
as soon as the native method returns.  This means that any object
references you have in static storage have bogus values when you
call the native method again, unless you get a global reference.
(See the programmer's guide again.)  The worst thing that can
happen is that you have an old reference to an object that has
been freed, and the reference number has been reused, and it now
refers to a completely different object.  Not so bad, unless it's
an object of the same class.  (It's not so bad if it's a different
class because you'll get an exception when you try to use it - if
it's the same class, you probably won't get an exception.)

Barbara Morris



As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.