[Xotcl] Can somebody tell me the creation and destruction
processes that go on "behind the scenes" in XOTcl?
Gustaf Neumann
neumann at wu-wien.ac.at
Wed Mar 1 10:05:43 CET 2006
Dear Matthew,
> The extra call to destroy occurs when the command interpreter closes, so
> must mean that MyBase was not properly destroyed because "next" was not
> called. This is probably the intended behaviour, but it is difficult to work
> it out from the examples given in
> http://media.wu-wien.ac.at/doc/tutorial.html.
>
you are right, the documentation should be improved. I have just added a
paragraph
adressing this point.
The destruction of objects is performed by the c-level method destroy of
::xotcl::Object.
The method destroy is a method like every other method in xotcl, asides
from its
side-effects, it is no way magic or special. If an application class
overwrites the
destroy method, and does not call "next", Object->destroy will not be
called, the
object will not be destroyed.
> Can somebody tell me the creation and destruction processes that go on
> "behind the scenes" in XOTcl?
>
You can ask xotcl to tell you, what's going on. Consider the following
filter
method implementing a trace. Before and after each invocation of a method,
the filter spits out a single line. We register the filter for all
instances of
all objects (as an instfilter for Object):
Object instproc f args {
puts "call [self]->[self calledproc]"
set r [next]
puts " [self]->[self calledproc] returns '$r'"
return $r
}
Class C
Object instfilter f
puts ==================
C c1
puts ==================
c1 destroy
puts ==================
Object instfilter ""
If we run the script, we get the following output.
==================
call ::C->c1
::C->c1 returns ''
call ::C->unknown
call ::C->create
call ::C->alloc
::C->alloc returns '::c1'
call ::xotcl::Class::Parameter->searchDefaults
::xotcl::Class::Parameter->searchDefaults returns ''
call ::c1->configure
::c1->configure returns '0'
call ::c1->init
::c1->init returns ''
::C->create returns '::c1'
::C->unknown returns '::c1'
==================
call ::c1->destroy
call ::C->instdestroy
::C->instdestroy returns ''
::c1->destroy returns ''
==================
If we create an Object via "C c1", we call a method c1 of Object. since this
is not defined, "C unknown" is invoked. For all classes, the predefined
unknown handler "create"s an object with the specified name. create
initiates the creation protocol,
- starting with "alloc" (registering the object as command, allocating
memory),
- calling "searchDefaults" (for setting the default values specified
via parameters),
- calling "configure", to overwrite some of these values and to specify
additional values,
- calling "init" to perform additional application-level
initializations, based on
the default and configured values.
destruction is much simpler. "destroy" is called on the object level,
"instdestroy"
is the counterpart of "alloc" on the class level (the class manages the
object,
allocates and destroys it, knows its instances, etc.)
> Also, it would be helpful if the differences between XOTcl and other OO
> languages, say C++, were highlighted as I know I have made assumptions which
> turn out to be wrong.
>
There are certainly many differences between a highly dynamic oo
language and e.g. C++.
Maybe some can start writing his gotchas into a wiki page. See as well
the distinction
between call-oriented vs. object-oriented in
http://mini.net/tcl/XOTcl
Hop this helps
-gustaf
More information about the Xotcl
mailing list