[Newbies] Proper object removal
norbert at hartl.name
Wed Jun 4 07:55:11 UTC 2008
On Wed, 2008-06-04 at 00:04 -0400, Rob Rothwell wrote:
> After much help already, I think I need some training in proper object
> When my application creates an object and stores it in an
> OrderedCollection, and than wants to delete it, I am trying to do so
> quite explicitly with something like:
> self selected do: [:each |
> self abstractors remove: each.
> each := nil.
> which removes the object from my application (it's collection), and
> yet when I look for my object in the system with
> DataAbstractor allInstances.
> I still see the object I removed, even with an explicit Smalltalk
> garbageCollect or garbageCollectMost. Anything I create just seems to
> hang around forever.
> Any help understanding what I need to do to make sure my objects
> really go away when I am done with them would be greatly appreciated!
The objects are still referenced in the collection you get
from self selected. The line with "each := nil" is useless
as each is only a temporary variable. I assume that you want
to empty the selected collection as well. you could do
self selected copy do: [:each |
self abstractors remove: each.
self selected remove: each.
More information about the Beginners