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

itsme213 itsme213 at hotmail.com
Tue Feb 26 23:48:27 UTC 2008


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'.

Now I have to make sure that no other objects retain any (effective) 
reference to X.

What are some best practices for doing this?

My current thought:
1. Every accessor of every instVAr for all relevant objects can do a 
check-and-clean before returning a value.

AnyClass>>aSingleObjAccessor
  singleInstVar isDeleted ifTrue: [singleInstVar := nil].
  ^ singleInstVar

AnyClass>>aCollectionAccessor
  collInstVar removeIf: [:x | x isDeleted].
  ^collInstVar

2. Perhaps I should also use weak-refs to X wherever possible, so X could be 
GC'd before all its incoming refs are check-and-cleaned? How does one 
actually do this?


I suspect I am missing far more elegant solutions.

All pointers :-) appreciated.

Thanks - Sophie






More information about the Squeak-dev mailing list