cyclic looping with [0 == object] whileFalse: [object := objectnextObject].

Rob Withers reefedjib at
Mon Nov 5 18:44:29 UTC 2007

Tom, the original loop that was looping forever was the method 

    | object |
    object _ starter.
        [0 == object] whileFalse: [
            object isMorph ifTrue: [object removeProperty: 
            object _ object nextObject].
        ] ifError: [:err :rcvr | "object is obsolete"
            self forgetAllGrabCommandsFrom: object nextObject].

where starter was set to "self someObject".   more below...

----- Original Message ----- 
From: "Tom Phoenix" <rootbeer at>

> On 11/5/07, Rob Withers <reefedjib at> wrote:
>> What gaurantees that doing loops with #nextObject won't cause cyclic 
>> looping
>> whereby you process the same set of objects over and over again?
> I think that would be the surrounding code. Certainly sending
> #nextObject can't always succeed; it should eventually run out of real
> objects and return zero. If you send #nextObject to 0, a SmallInteger,
> it should fail for sure.

I thought of a possibility.  It could be that I am creating objects 
(BlockContexts and MethodContexts) as fast as I process them in this loop. 
If the loop is creating objects, then they are bound to be at the end of 
memory and I am bound to not be able to catch up to them.  In this case, my 
#ifTrue: msg is a real msg creating a real BlockContext each time through 
the loop, because of my Compiler changes, and the associated MethodContexts 
are being created too.  (My addition of 
anOrderedCollection>>#add:/#addLast:/#grow... are being recorded as well). 
Each time through a new instance of the BlockContext is being created.

That sucks.  I can't do anything about it.

>>    object _ nil.
>>     [0 == object or: [count > 500000]] whileFalse: [
> This should drop out when 0 is encountered, or when 500000 objects
> have been counted. The first should eventually happen, and so should
> the second. Are you sure you let this loop run long enough?

My modified loop does stop because of count > 500000.  Then I was able to 
see the cyclic looping.

> But I've got to say it seems odd that the loop starts at nil. Most
> users of #nextObject don't use it like that, since nil isn't
> guaranteed to be at any particular place in the enumeration of all
> objects. Shouldn't it be something like this?
>  object := self someObject.

I switched to this.

>> What guarantee is there supposed to be that #nextObject won't loop back 
>> into
>> a cycle?
> Zero is the guarantee.
>> What did I do to break that guarantee and how can I reestablish
>> it?
> I don't think you broke it, unless you redefined
> SmallInteger>>nextObject or something like that.
> Hope this helps!

It helps me understand!  Thanks!  I don't know what I can do about it.


More information about the Squeak-dev mailing list