Native finalizer.
Ben Gardiner
BenGardiner@nanometrics.ca
Mon Jul 13 16:54:00 GMT 2009
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
More information about the Java
mailing list