No registered users in community xowiki
in last 10 minutes
in last 10 minutes
Re: [Xotcl] Deleting objects
From: Gustaf Neumann <neumann_at_wu-wien.ac.at>
Date: Mon, 12 May 2003 17:10:27 +0200
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
Date: Mon, 12 May 2003 17:10:27 +0200
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