[squeak-dev] Best practice(s) to delete an object?

Jeffrey Straszheim jstraszheim at comcast.net
Thu Feb 28 00:40:44 UTC 2008


So, If I understand you, you have a graph of object that refer to each 
other and you want to remove an object from that graph?

You have two relatively straightforward choices:

1. Have the object mark itself as deleted, and then ensure that all 
clients of that object test its status before using it.

2. Do a (depth first) walk of the entire graph whenever you delete an 
object to remove it.

The problem with 1 is the object may never get GC'ed.  If you use weak 
references that will help, except now it might get GC'ed to early.  A 
solution is to hold the objects in some global structure with hard 
references and remove it from their when done with it.  Also, a perhaps 
bigger problem is you may forget the write the test code at some point 
and break the protocol.
 
The problem with 2 is that it will be expensive every time you remove an 
object.

Those are your trade offs.


itsme213 wrote:
> I have this object, X, I want to delete (typically from within the context 
> of some other object Y). So I remove it from Y (set some Y instVar to nil, 
> or remove it from some collection instVar of Y). I mark X 'deleted'.
>   

-- 
Jeffrey Straszheim
http://straszheim.50megs.com




More information about the Squeak-dev mailing list