.... > While all code in newer Tcl.xs looks correct, I want to figure out > refcounting problem in more detail for myself.
I tried this and that, understood refcounting of proper CVs, understood new "perlsub" Tcl object, so on. I, for myself, came into conclusion that reference counting of anonymous subs/ closures could not be done within current scheme. Anonymous sub within following code: .... use Tkx; my $mw = Tkx::widget->new("."); my $count; my $but = $mw->new_button(-text => "Hit me"); $but->configure(-command => sub { $count++; }) for 0..5; print Tkx::info_commands("::perl::*"), "\n"; .... has different "CODE(xxxx)" stringification each time. However, I think there is a way out for a good refcounting. As long as same anonymous subroutine always has same "xcv_start" and "xcv_root" (whereas it could have different "xcv_padlist" within different invocations) this way it could be detected when same sub is used, even within different CV. Let me explain. Let us curently consider using "old" way via CreateCommand/Tcl_PerlCallWrapper, (without "perlsub" Tcl object yet, but will return to that code later, after proof-of-concept will work) Instead of Tcl_PerlCallWrapper, should be used in Tcl.xs a similar procedure, say, Tcl_PerlCallOp, which will invoke code using "OP*" and padlist (instead of just CV); so this way we're a bit deeper in Perl internals, but this is probably the only way to not waste extra resources. So we'll be not creating Tcl command when another closure within same subroutine invoked. Gisle, as a much better expert of Perl internals, do you have disproof of a concept? Vadim.