> > 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();
> }
Well, that does not seem like a very good idea. Using the JVM
as a "pseudo GC" for Tcl objects seems like we are just asking
for trouble.
> 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.
Good point. I think it might actually be better to put a panic()
in the finalize() method for a Tcl object, that way we will know
that someone forgot to decr a ref count instead of silently leaking
Tcl objects.
> 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:
I was under the impression that the interp would always do a
preserve() for you because of this exact case. When a new interp
result is set, it would call release().
> String result;
> TclObject resObj;
>
> resObj = interp.getResult();
> resObj.preserve();
> result = resObj.toString();
> resObj.release();
>
> -- Jiang Wu
> [EMAIL PROTECTED]
Mo DeJong
Red Hat Inc
----------------------------------------------------------------
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/[email protected]