Storing C++ data in an instance field using CNI?

Tom Tromey tromey@redhat.com
Wed May 26 16:37:00 GMT 2004


>>>>> "Stanley" == Stanley Brown <stanley.brown@zimmer.com> writes:

Stanley> Also remember to override the finalize method of your Java
Stanley> object that is storing the native struct to call a native
Stanley> method to free/delete the native struct.  Very important!!
Stanley> If you dont do this C/C++ will not deallocate the memory
Stanley> reserved for your native struct when the Java class is GCed.

I suspect it is better these days to use a PhantomReference to do the
cleanup.  The problem with finalize() is that, if you are writing a
library, you may have to deal with the situation where another
finalizer resurrects your object.

Tom



More information about the Java mailing list