× 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.



One additional question how does RPG get a hold of the returned objects and
use them to perform other tasks like print or insert into a PF etc.

Thanks

----- Original Message -----
From: <bmorris@ca.ibm.com>
To: <rpg400-l@midrange.com>
Sent: Friday, February 08, 2002 1:09 PM
Subject: Re: Calling java methods


> >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
>
> _______________________________________________
> This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
> To post a message email: RPG400-L@midrange.com
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/cgi-bin/listinfo/rpg400-l
> or email: RPG400-L-request@midrange.com
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.
>



As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.