Using CNI to call compiled java from C++

Stéphane MILLET stef.millet@wanadoo.fr
Wed Oct 22 07:04:00 GMT 2003


> If you do a "new" on a Java class from C++, it is allocated using 
> libgcj's garbage collector, not the default C++ allocator. So, it will 
> be deleted when the collector decides it is unreachable, just like any 
> other Java object.

I agree with your answer but don't understand how the collector decides that the object isn't reachable anymore. The Java object is allocated and used in the C++ side of the program, so... Is it declared unreachable as soon as you exit the current function like a local variable ? or is there a function that makes an object reclaimable ?

In my program, at the moment the finalizers of those types of objects are never called. 

Regards

Stephane MILLET


> Message du 22/10/03 00:06
> De : Bryce McKinlay <bryce@mckinlay.net.nz>
> A : stef.millet@wanadoo.fr
> Copie à : java@gcc.gnu.org
> Objet : Re: Using CNI to call compiled java from C++
> On Oct 22, 2003, at 6:59 AM, Stephane MILLET wrote:
> 
> > I'm working on a C++ application and wanted to use Java code in it. To
> > do that, i've been trying to use CNI functions to call compiled java
> > code with their gcjh produced headers. I first create the JVM, then
> > attach the current thread as defined in the manual. Then, when I need a
> > particular java class instance, i do a new in C++ and use the instance.
> > But, how and when will this object be deleted ?
> 
> If you do a "new" on a Java class from C++, it is allocated using 
> libgcj's garbage collector, not the default C++ allocator. So, it will 
> be deleted when the collector decides it is unreachable, just like any 
> other Java object.
> 
> Regards
> 
> Bryce.
> 
> 
>



More information about the Java mailing list