[Xotcl] Deleting objects
Gustaf Neumann
neumann at wu-wien.ac.at
Mon May 12 17:10:27 CEST 2003
On Monday 12 May 2003 16:42, MichaelL at frogware.com wrote:
> Look at the following code, which is meant to be a stripped-down and
> simplified version of my real code:
hi Michael,
this mail ist the fastest to answer:
>
> Class DatabaseMgr
> DatabaseMgr instproc openDatabase {} {
> Database [self]::db
> }
>
> Class Database
> Database instproc init {} {
> puts "init [self]"
> }
>
> Database instproc destroy {} {
> puts "destroy [self]"
> }
In the method above, you are overwriting the "Object instproc destroy",
which initiates the physical destroy. Add a "next" as in:
Database instproc destroy {} {
puts "destroy [self]"
next
}
>
> DatabaseMgr dbmgr
>
> dbmgr openDatabase
>
> dbmgr::db info class
> dbmgr::db destroy
> dbmgr::db info class
>
> The second call to "info class" should fail but doesn't. That's because
> the object isn't actually destroyed. (In my real code the objects have
> dynamically generated names; I used the static names to simplify the
> example.)
>
> The above style is similar to the style of code used in xoRBAC (eg,
> factories & self-destruction) so I'd be surprised if it too wasn't leaking
> objects.
>
> After the above code run this code:
>
> dbmgr info class
> dbmgr destroy
> dbmgr info class
>
> Now both dbmgr and dbmgr::db are destroyed--but note that the "destructor"
> gets called twice at this point!
since dbmgr::db exists at this point, the destroy of dbmgr will trigger
the destroy of the child objects. That is ok.
best regards
-gustaf
--
Univ.Prof. Dr.Gustaf Neumann
Abteilung für Wirtschaftsinformatik
WU-Wien, Augasse 2-6, 1090 Wien
More information about the Xotcl
mailing list