CNI and garbage collection

Marcus G. Daniels
Thu Jul 19 19:49:00 GMT 2001

>>>>> "BM" == Bryce McKinlay <> writes:

BM> So how to keep a pointer, associated with a given class or object,
BM> to your native object? One solution is to declare a field (in
BM> Java) of the type gnu.gcj.RawData. This class is treated specially
BM> by the garbage collector, and can be used for storing a pointer to
BM> some native, non-Java object. RawData fields will not be marked by
BM> the GC, so you need to dealocate them explicitly (perhaps from a
BM> finalizer).

Works like a charm.  Thanks very much. 

MD> But what about the C++ objects inside of the Java object?  Is
MD> there a special way to allocate them?

>>>>> "JS" == Jeff Sturm <> writes:

JS> You could try to override the "new" operator to place C++
JS> objects where they will be traced.  But that exposes details of the
JS> collector implementation, and could have other pitfalls when done
JS> together with libgcj.  See boehm-gc/include/gc_cpp.h for more info.

Cool, thanks for the pointer.  (And to both of you for pointing out that
Boehm GC doesn't move things!)

More information about the Java mailing list