This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Storing C++ data in an instance field using CNI?
- From: Tom Tromey <tromey at redhat dot com>
- To: Stanley Brown <stanley dot brown at zimmer dot com>
- Cc: java at gcc dot gnu dot org
- Date: 26 May 2004 10:13:02 -0600
- Subject: Re: Storing C++ data in an instance field using CNI?
- References: <40B4A105.90909@zimmer.com>
- Reply-to: tromey at redhat dot com
>>>>> "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