Hi Dario, On 9 April 2018 at 10:00, Trussardi Dario Romano <dario.trussa...@tiscali.it> wrote: > Ciao, > > in the Pharo 4.0 image i have a IdentityDictionary with ten items. > > Now when i reset the dictionary the system behaves as follows: > > Version A) resetAllLocks > > locks keysAndValuesDo:[:k :v | locks > removeKey: k ifAbsent: [self halt]] > > > Not all items are removed fro the dictionary. > > > Version B) resetAllLocks > > locks keys do:[:k | locks removeKey: k > ifAbsent: [self halt]] > > All the items are always removed. > > > Considerations about it?
The first version modifies the collection while iterating over it - generally a bad thing to do. The second version creates a new collection of keys and then uses it to remove the items - much safer. If you set a breakpoint in the methods and step into each message send you'll be able to see the difference. Cheers, Alistair