Re: Native finalizer.

Ben Gardiner <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.