Nat! bio photo


Senior Mull.

Twitter RSS


[NSEnumerator nextObject] vs. [NSArray objectAtIndex:]

One can probably write books about this subject.

I am not sure since when, but -[NSEnumerator nextObject] at least when enumerating an NSArray is returning an autoreleased object. Is this something new or has this been done since the dawn of time ? This pisses me off annoys me greatly, because autoreleased objects make it harder for me to debug. I prefer my objects to dealloc as soon as possible, because if they fail, I have a useful stacktrace.

So I rewrote many of my non-critical loops to use the familiar for(;;) -[NSArray objectAtIndex:] "pattern". (I am surely not using Foundation code for any of my critical loops, he he)

The question I asked myself is this though.:Why is -NSArray objectAtIndex:] not returning an autoreleased object ? It is inconsequential to return an autoreleased object in -[NSEnumerator nextObject] but not in -NSArray objectAtIndex:].

Should I file a bug for orthogonality and misery ? I don't think so. Let sleeping poodles lie.