This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]