This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Native finalizer.
abhishek desai wrote:
Hi,
Is there any way to assign a native finalizer method per object to be
called when the object gets garbage collected ? I want to assign this
in the native layer.
I think you'll find an example of this in natReference.cc:
void
::java::lang::ref::Reference::create (jobject ref)
{
// Nothing says you can't make a Reference with a NULL referent.
// But there's nothing to do in such a case.
referent = reinterpret_cast<gnu::gcj::RawData *> (ref);
copy = referent;
if (referent != NULL)
{
JvSynchronize sync (java::lang::ref::Reference::lock);
// `this' is a new Reference object. We register a new
// finalizer for pointed-to object and we arrange a special
// finalizer for ourselves as well.
_Jv_RegisterFinalizer (this, finalize_reference);
_Jv_RegisterFinalizer (referent, finalize_referred_to_object);
gnu::gcj::RawData **p = &referent;
_Jv_GCRegisterDisappearingLink ((jobject *) p);
add_to_hash (this);
}
}
,Ben