On 11 Apr 2008, at 18:27, Quincey Morris wrote:

On Apr 11, 2008, at 09:51, Alastair Houghton wrote:

It doesn't, but you might conceivably have methods that take an NSEnumerator and do something with the objects it returns. Hence the utility of "nextObject".

Ah, I see - simultaneous cake-having and cake-eating. :)

:-D Indeed. Which in this case is almost possible with -retain/- release, but not with GC.

Isn't this problem similar to the GC-finalize problem, where you can't safely do most object resource releasing in finalize, so you have to do it earlier. Maybe the answer is the same, you give the object an "i'm done with you" method that the user of the object calls. After that, you would be able to cache and re-use the object. (IOW, I guess, re-invent reference counting for the object.)

Yes, perhaps that is best. And I suppose if the message in question happened to implemented as a category on NSObject as a do-nothing method, you'd be able to use it for ordinary NSEnumerators as well as ones that return object wrappers.

Even though it isn't automatic, I quite like that approach. Now if we all co-operate to choose the name of the method, it'll work with third- party code (where necessary) without modifications, and if Apple was to choose to adopt it in future, things you Just Work(TM).

How about

  -(void)makeAvailableForReuse;

or

  -(void)allowReuse;

or even

  -(void)discard;

Anyone have any preferences? I quite like -discard. So you'd do something like

  while ((obj = [enumerator nextObject])) {
    // Use obj

    [obj discard];
  }

or even (and slightly safer in many cases)

  for (; obj = [enumerator nextObject]; [obj discard]) {
    // Use obj
  }

This could also easily be made to work with fast enumeration.

If everyone likes -discard, I'll knock-up a page on CocoaDev describing the idea.

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to