Hello back, from the other thread at c.l.j.p :-)
natar...@gmail.com <
natar...@gmail.com> wrote:
> Thanks for pointing 'trace' .
> The below example is simple enough , once variable associated
> with a collection is updated/written , we can delete it :)
> %set a [get_ports rest*]
> %trace add variable a write "unset_collection a"
> Now I see somemore problems !
> 1) how can we know to which variable this collection is being set
> 2) another scenario would be nested commands ,
> I have no clue on how to get around this
Not to forget, that traces fire *after* the write, and by that time
you might no longer know which collection to set free. The trace
handler would need to be a bit smarter: e.g. define "_a" as backstore
of "a", and first check if $_a equals $a (then: no-op), otherwise see
if "_a" was filled (then set it free), finally fill "_a" from "a",
which already has new value.
As for setting up the traces, you'd define a procedure "setLTM" which
will check if the variable already has such a trace and if not, then
set up the trace. Usage:
% setLTM a ;# initialize variable for LTM (LifeTimeManagement)
% set a [get_ports rest*] ;# now traces do the rest.
% # unsetLTM a ;# remove traces, after cleaning up current ref.
Then object's lifetime is tied to that one variable. It could then
also be tied to another LTM'ed variable, but then it would be freed
already when *any* of the vars is overwritten, not just after *all*
are.
If that was not acceptable, then it is easy to change the traces such,
that they will use an tcl-side ref-counting mechanism to decide
what objects really are used by no LTM'ed variable anymore. References
in non-LTM'ed variables would correspond to Java's "WeakPointer".
That would bring you:
% setLTM a ;# initialize variable for LTM (LifeTimeManagement)
% set a [get_ports rest*] ;# now traces do the rest.
% setLTM b
% set b $a
% set a "" ;# object not freed, because ref-count still 1
% set b "" ;# now freed.
That's however still unsafe against looping reference chains.
What part of the plot actually generates the id's (like 0x11)
to represent the real entities? Is this on Java side, or part
of the Tcl/CCI adaption?
Will you need to implement the Tcl-versions of "get_ports",etc.,
or just use these commands and thereby take care that a ref doesn't
accidentally disappear too soon ?
PS: What are your levels in each of Tcl, Java and CCI ?