You made a good catch here. Here is what I think is happening. This is a
problem only when a pure Java TclObject is converted into a native C
Tcl_Obj.
Suppose we create a TclObject on a simple Java string "a b c" (TclString).
(In your email, the TclObject is an ArrayObject, which is also a pure Java
TclObject.) Before the conversion, we have:
TclObject (A)
contains "a b c"
Then if we do TclList.setListFromAny() on (A), TclBlend implicitly creates a
C Tcl_Obj to represent the list (a b c). The above TclObject is modified
into:
TclObject (A)
contains Tcl_Obj (1)
Unfortunately, the Tcl interpreter is not aware of the Tcl_Obj (1). So the
interpreter would not clean up this object. The Tcl_Obj (1) has to be
cleaned up by TclBlend. We can't clean up the Tcl_Obj (1) unless TclObject
(A) is cleaned up. And TclObject (A) is only cleaned up by the garbage
collector.
But we have decided that it is a bad idea to clean up Tcl_Obj inside the
garbage collector. So we remove those code. As a result, Tcl_Obj (1) is
not cleaned up by anyone.
-- Jiang Wu
[EMAIL PROTECTED]
> -----Original Message-----
> From: Daniel Wickstrom [mailto:[EMAIL PROTECTED]]
> Sent: Friday, October 20, 2000 1:54 PM
> To: [EMAIL PROTECTED]
> Subject: [Tcl Java] possible memory.
>
>
> >>>>> "Dan" == Dan Wickstrom <[EMAIL PROTECTED]> writes:
>
>
>
> Dan> It appears that the splitList method is only called from
> Dan> within the setListFromAny method The setListFromAny method is
> Dan> then used in most of the TclList methods. It's not clear to
> Dan> me why the TclList object and the underlying Tcl_Obj wouldn't
> Dan> get cleaned up.
>
>
> Further investigation shows that the corresponding setListFromAny call
> is made from the TclList.getString method. As an example here is a
> section from ArrayObject.java:
>
> case OPT_SET:
> if (numArgs != 2) {
> throw new TclNumArgsException(interp, optionIdx + 1, argv,
> "indexList value");
> }
> if (convert == false) {
> throw new TclException(interp,
> "-noconvert flag not allowed for the \"set\"
> sub-command");
> }
>
> indexListObj = argv[optionIdx + 1];
> numDims = TclList.getLength(interp, indexListObj);
> if (numDims == 0) {
> subArrayObj = javaObj;
> subArrayClass = dereferenceClassDims(interp, javaClass, 1);
> index = 0;
> } else {
> // Dereference all but the last dimension specified. Set
> // the value of index'th element of the "subArrayObj" to
> // the value in argv[optionIdx + 2].
>
> subArrayObj = dereferenceArrayDims(interp, javaObj,
> numDims, indexListObj);
> subArrayClass = dereferenceClassDims(interp,
> javaClass, numDims);
> index = TclInteger.get(interp,
> TclList.index(interp, indexListObj, numDims - 1));
> }
>
> // Set the value of the index'th element of
> "subArrayObj" to the value
> // in the TclObject argv[optionIdx + 2].
>
> setArrayElt(interp, subArrayObj, subArrayClass, index,
> argv[optionIdx + 2]);
> interp.resetResult();
> return;
>
> The TclList.getLength method converts indexListObj to a TclList object
> which uses an underlying Tcl_Obj to hold the internal rep. At the end
> of this case statement, it returns leaving indexListObj with no
> references. The jvm garbage collects indexListObj, but the underlying
> Tcl_Obj is left stranded and results in a memory leak.
>
> -Dan
>
>
> ----------------------------------------------------------------
> 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
>
----------------------------------------------------------------
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