> -----Original Message-----
> From: Mo DeJong [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 19, 2000 12:05 PM
> To: Jiang Wu
> Cc: Dr Wes Munsil; [EMAIL PROTECTED]
> Subject: RE: [Tcl Java] Re: [Tcl Java] another deadlock
> 
> On Mon, 19 Jun 2000, Jiang Wu wrote:
> > explicitly free Tcl objects using "TclObject.preserve()" and
> > "TclObject.release()".
> 
> Tcl Blend users should be doing this already.

I have seen several places where this was not done.  Instead the code relies
on the Java GC to invoke the TclObject.release() implicitly in the
'finalized() method.  In TclBlend's CObject class:

CObject (
    long objPtr)
{
    this.objPtr = objPtr;
    incrRefCount(objPtr);
}

protected void finalize() throws Throwable
{
    if (objPtr != 0) {
        /*
         * If the object is finalized while the reference is still valid, 
         * we need to sever the connection to the underlying Tcl_Obj*.
         */

        decrRefCount(objPtr);
    }
    super.finalize();
}

static final native void
decrRefCount(
    long objPtr);               // Pointer to Tcl_Obj.

If the user had called "TclObject.release()" properly, then the native C
object would have been free'ed already before the Java object is finalized
by the GC.  Then the call to "decrRefCount(objPtr)" in the finalized()
method of a CObject would not invoke Tcl's C function FreeTclObject() during
GC.  Maybe we can try to comment out the "decrRefCount()" in the above
finalized() method to test if it is indeed the "FreeTclObject" that is
causing the deadlock in the GC.

For example, in the Shell.java, there are code such as:

        interp.getResult().toString();

Now, interp.getResult() can potentially return a CObject.  Since nothing
stored the reference to the returned CObject, the corresponding native C
object is free'ed implicitly by the GC during finalization.  For this code
to be really safe, it should be:

      String result;
      TclObject resObj;

      resObj = interp.getResult();
      resObj.preserve();
      result = resObj.toString();
      resObj.release();

-- Jiang Wu
   [EMAIL PROTECTED]

----------------------------------------------------------------
The TclJava mailing list is sponsored by Scriptics Corporation.
To subscribe:    send mail to [EMAIL PROTECTED]  
                 with the word SUBSCRIBE as the subject.
To unsubscribe:  send mail to [EMAIL PROTECTED] 
                 with the word UNSUBSCRIBE as the subject.
To send to the list, send email to '[EMAIL PROTECTED]'. 
An archive is available at http://www.mail-archive.com/tcljava@scriptics.com

Reply via email to