On Wed, 04 Jun 2008 12:12:59 +0200, Bert Freudenberg wrote:
On 04.06.2008, at 10:32, Klaus D. Witzel wrote:
On Wed, 04 Jun 2008 09:55:11 +0200, Norbert Hartl wrote:
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.
Not 100% useless, since temporary variables (and arguments, for that
matter) survive any attempt, from within the same method, to garbage
collect them:
{'this ', 'and ', 'that'} collect: [:each | ].
Smalltalk garbageCollect.
{thisContext tempAt: 1} inspect
first line: create some object and make a temp var point to it.
second line: invoke GC.
third line: see what's still pointed to by the temp var.
Yikes. Klaus, please keep the hair-splitting to squeak-dev if possible.
Ah. Didn't know that enumerating+removing with a block with argument
+ GC'ing in the same method, belongs to hair-splitting. Instead, I always
thought that's one of the reasons that at least one to-be-removed object
is guaranteed to not go away.
But anyways, thanks for letting me know ;)
Assigning to a block parameter is just wrong.
You better read before you write (the way you most often do indeed ;) then
you'd find that I didn't write any assignment to anything. Instead, I
ignored that and pointed to a potential beginner's problem. Sorry you
didn't like that ;)
Setting temps to nil is unnecessary in any normal method. If your code
actually needs to worry about this, then you left the beginner
playground.
And if he does removal+GC+check for success in the same method? I cannot
see whether someone just copies arbitrary statements given in a response
to a question, or carefully puts them into separate methods, in his code
in his .image, now or never ;)
Rob: Here's a recipe to find out what is keeping your instances from
being garbage-collected:
http://wiki.squeak.org/squeak/2631
- Bert -
_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners