View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] results of the poll

From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Mon, 4 Mar 2002 18:47:47 +0100

On Monday 04 March 2002 18:21, Zoran Vasiljevic wrote:
> > suggestion implemented in C. Actually there is no need
> > in general for using tcl-variables to implement volatile
> > objects (we could handle this on a pop of stack frames),
> > but at least for pure tcl-procs, var traces are the simplest
> > implementation. The current implementation (purely in C)
>
> It is not clear: does the C implementation use internal stack
> for garbage collection or the Tcl-trace variable mechansim?

 the var-trace mechanism

> It is important to know when doing (or not doing!) such
> constructs:
>
> Class foo
> foo instproc test args {}
>
> [foo new -volatile] test ; # object leak ?

 this sets as a side effect a tcl variable in the current
 scope. if the scope is e.g. a tcl proc, it will be
 automatially unset, when the scope is left.

> In case of volatile implementation with var traces,
> one should do:
>
> set bar [foo new -volatile]
> $bar test

 Note, that this is essentially the same as
 above. the call of [foo new] cannot set a
 vartrace on the "bar" variable. The result
 of the "new" is a tcl_obj, and not a variable.
 the tcl_obj is bound to the variable bar...
 so, the magic of the object deletion happens
 via another variable, that is set as a side
 effect. these magic variables are named similarly
 to the object name: in the example

    set bar [foo new -volatile]

 the objname will be ::xotcl::__#1 (or ...__#2, etc),
 the magic variable is __#1. therefore, one can
 refer from the object name to the variable name via

    set vn [namespace tail $bar]
    unset $vn

 will trigger the deletion of the object
 created with new. There is a potential danger
 of name conflics, but if one follows the rule:
 don't start user-variable names with "__",
 everyting will be safe.

 I have used this example with the manual unset
 for explanatory purposes. Under most conditions you will
 not need to unset the magic variable by hand....

 hope that this explains the details.

 best regrads
-gustaf