[Newbies] Proper object removal

cdrick cdrick65 at gmail.com
Wed Jun 4 12:19:51 UTC 2008


2008/6/4 Rob Rothwell <r.j.rothwell at gmail.com>:

> On Wed, Jun 4, 2008 at 3:55 AM, Norbert Hartl <norbert at hartl.name> wrote:
>
>> Hi



>
>> 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
>>
>> DataManager>>deleteSelectedAbstractors
>>   self selected copy do: [:each |
>>   self abstractors remove: each.
>>   self selected remove: each.
>> ]
>
>
> So...why would I use a copy (self selected copy) in this case?  Is that a
> clue to my misunderstanding?
>
> Rob
>


because

self selected do: [:each |
  self selected remove: each ] is to avoid ... as it iterates on the
collection on wich you're removing elements...

Try

aColl:=#(1 2 3) asOrderedCollection.
^aColl do: [:ea | aColl remove ea ]

see here: http://bugs.squeak.org/view.php?id=6937

Cédrick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080604/f0bd1f13/attachment.htm


More information about the Beginners mailing list