Warning: Tcom has volatile handles


While playing with Tcom with both an interactive Wish and Melissa
Shrumpf's nice ComTree, I discovered one thing that might discourage
newcomers (to COM and/or Tcom) like me: the handles returned by
[::tcom::ref createobject] are *volatile*, i.e. they disappear as soon
as Tcl holds no more reference to the initial (Tcl) object created to
wrap them.

The net effect is that you type in wish:

% package require tcom
% ::tcom::ref createobject SomeApi.SomeClass

But if then you copy and paste the above returned handle in:

% ::tcom::info interface ::tcom::handle0x00939CB0

you get an error saying the interface cannot be obtained.

The workaround, of course, is to avoid the string-only path of copy/
paste and use a variable keeping a reference alive:

% set h [::tcom::ref createobject SomeApi.SomeClass]
% ::tcom::info interface $h

This quirk places Tcom in the confidential circle of "Feather-like"
extensions, meaning they violate the EIAS principle. Getting out of
this circle involves explicitly managing the lifecycle of such opaque
objects, like file handles in Tcl. But I can understand that in the
COM world it is better the way it is, because APIs tend to generate
many sub-objects from a root one (e.g. interfaces), and tying their
lifecycle to that of internal reps of Tcl values is a quick solution
for the script programmer. Maybe a warning in the docs is all there's
to do...