Subject: Re: Tcl_Interp reference counting? - DN [1]
Paul Duffin <pduffin@mailserver.hursley.ibm.com> - 11 Oct 1999 - comp.lang.tcl
Carsten Orthbandt wrote:
>
> Since I pass lots of Tcl_Interp* around in my code, I use a smart pointer
> for that. Since Tcl_Interp* doesn't seem to be reference counted, I have to
> use some quite complicated rules to ensure proper cleanup and ownership.
> Is there any way to have a reference count in Tcl_Interp*. I understand that
> the Tcl core wouldn't need it, but I for performance reasons I'd rather not
> store the reference count in the user data hash.
>
Protection of Tcl_Interps is a little bit confusing but I think the main
reason why it is not reference counted is that you can get into all
sorts of reference counted cycles which would require a GC to clean up.
(Please lets not start that discussion, go to c.l.python if you want to
take part in one of those).
What you are supposed to do is if you have a pointer to a Tcl_Interp
is one of two things. If the pointer is short lived (e.g. on the stack)
then you should call
Tcl_Preserve ((ClientData) interp);
:
:
Tcl_Release((ClientData) interp);
around the call which could result in the interpreter being destroyed.
If the pointer is long lived (e.g. on the heap) then you should register
a function which is called when the interpreter is deleted and does
the clean up necessary.
Tcl_CallWhenDeleted (...)
Note that lots of things which are associated with an interpreter such
as commands, associations and namespaces (which you explicitly create
yourself) have a delete function which will be called before the
interpreter is deleted so you can use that to do your cleanup.
--
Paul Duffin
DT/6000 Development Email: pduffin@hursley.ibm.com
IBM UK Laboratories Ltd., Hursley Park nr. Winchester
Internal: 7-246880 International: +44 1962-816880
Last modified
1999-10-19
1999-10-19
(195.108.246.51)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
