Having Trouble understanding CNI string allocation

Sebastian Kloska kloska@scienion.de
Mon Sep 27 12:22:00 GMT 2004


  Thank you very much --

  How's about these random errors when doing all String
  allocation dynamically (i.e. java::lang::String * is
  only used for one call and then forgotten). Is this
  explainable from within CNI or should I try to find
  the misbehaviour in the JDBC driver ?

  BTW I'm sing gcj-3.3.3 as shipped with Fedora Core 2

  Thanks

  Sebastian


Andrew Haley wrote:
> Sebastian Kloska writes:
>  > 
>  > In an attempt to reduce the calls to JvNewStringUTF I was trying
>  > to store the colum names I like it access in an array of
>  > 'java::lang::String *', but after initializatons (as a none static
>  > class array) and befor using these pointers in another class method
>  > the strings seem to be gone. So it seems I do not realy understand
>  > the concept of how long I'm alowed to hold a (valid ?) reference
>  > to an JAVA object (e.g. String) and that somehow the garbage
>  > collector is 'stealing' these from me....
> 
> The gcj garbage collector will recycle memory when it determines that
> there are no live references to it.  The gc won't look inside
> structures allocated by malloc() or the C++ runtime library's new().
> 
> If you want to make an array of 'java::lang::String *' you had better
> make it a JArray<jstring>, not a C++ array, and you'd better make sure
> that a pointer to that jarray is live in a Java object somewhere, or
> the strings will be deallocated.
> 
> Andrew.


-- 
**********************************
Dr. Sebastian Kloska
Head of Bioinformatics
Scienion AG
Volmerstr. 7a
12489 Berlin
phone: +49-(30)-6392-1708
fax:   +49-(30)-6392-1701
http://www.scienion.de
**********************************



More information about the Java mailing list