[Newbies] remove allInstances?

Tobias Pape Das.Linux at gmx.de
Fri Sep 23 17:47:31 UTC 2016


On 23.09.2016, at 15:03, Louis LaBrunda <Lou at Keystone-Software.com> wrote:

> Hi Joseph,
> Try:
> Books allInstances do: [:b | b become: nil].

I would advise against that. Become is a sledgehammer and you're about to crush ants with it.

What happens with 'a become: b' ? All occurrences of 'a' in the image are replaced by 'b' and (this is important) vice versa.
So, all 'b's are replaces by 'a'.

With your example, all occurrences of nil are replaced with an instance of Book, in the whole image. This is most probably _not_ what you want.

These two versions work better:

Books allInstances do: [:b | b becomeForward: nil].
Books allInstances do: [:b | b become: Object new].

The first avoids the 'vice versa' part of become: and is more safe, the second one
does the switcharoo with a new object every time, wich is also more safe.

Anyhow, I presume that your intent is to track down instances of Book wich you don't know where they are.

Maybe they are actually unreferenced already, so
	Smalltalk garbageCollect
can get already rid of them. 

If that does not help, you can try to track the references down by doing

	Books allInstances do: [:b | b chasePointers]

which will open a PointerFinder for each of the rouge object so you can inspect where they get referenced.

I hope this helps.

Best regards

> Lou
> On Fri, 23 Sep 2016 00:40:33 -0500, Joseph Alotta <joseph.alotta at gmail.com> wrote:
>> Greetings,
>> The main program I am working on now is called Books.
>> If I evaluate
>> Books allInstances => anOrderedCollection( aBook aBook aBook )
>> How do I set them all equal to nil like
>> Books removeAllInstances.
>> Books allInstances => anOrderedCollection().
>> Sincerely,
>> Joseph.
> -- 
> Louis LaBrunda
> Keystone Software Corp.
> SkypeMe callto://PhotonDemon
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

More information about the Beginners mailing list