> > The current Tcl.pm code works because it does '$srefs{"$s"} = $s'
> > instead of the '$srefs{"$s"}++' you do above. This keeps the code
> > alive even after $s and $t are cleared.
>
> Looking closer this isn't really true. The $srefs reference is not
in my example I intentionally did not stored reference to subroutine into a
hash, so to remain reference count intact, and to check whether distruction
come in proper order
As I realized afterwards, the root of a problem is a bit on other side,
namely why the module releases CVs.
> Consider this test program:
>
> use Tcl;
> use Devel::Peek;
> my $i = Tcl->new;
> my $cv = sub { $i };
> Dump($cv);
> $i->call("puts", $cv);
> Dump($cv);
>
> You will see that the REFCNT on the $cv is 1 before the $i->call and 3
> after. The reason it is 3 is that %anon_refs stores one reference and
> the client data of the Tcl command created stores another.
yes, I clearly understand that.
While all code in newer Tcl.xs looks correct, I want to figure out
refcounting problem in more detail for myself.
Vadim.