[Newbies] Re: Proper object removal

Norbert Hartl norbert at hartl.name
Thu Jun 5 12:02:26 UTC 2008


On Wed, 2008-06-04 at 14:41 +0200, Klaus D. Witzel wrote:
> 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 ;)
> 
I don't care if it is called hair-splitting or something different. I
must agree with Bert. I found it interesting but misplaced on beginners.
What you were talking about had nothing to do with the Problem Rob was 
asking (and to continue in Bert's words: If you use thisContext tempAt: 
you've left the beginner area already). With your first line you
confused even me and I'm little bit reluctant now to be called a
newbie ;)

Writing 

{ 'this', 'and', 'that' }

instead of

Array with: 'this and that'

let people like me assume there is some black magic happening. To under-
stand the problem dots instead of commata makes it clearer. So maybe you
can understand that while you are right you can spread uncertainty to
those which aren't that experienced (this includes me as well). And
to some who are that experienced it appears like hair-splitting ;)

Norbert 

> > 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 at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners



More information about the Beginners mailing list