• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Array of random, non-repeating numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Array of random, non-repeating numbers


  • Subject: RE: Array of random, non-repeating numbers
  • From: Jeff Laing <email@hidden>
  • Date: Fri, 14 Jul 2006 11:02:32 +1000

> From: Nir Soffer [mailto:email@hidden]
> - (void)swapObjectAtIndex:(unsiged)a withObjectAtIndex:(unsiged)b {
> 	id temp = [self objectAtIndex:a];
> 	[self replaceObjectAtIndex:a withObject:[self objectAtIndex:b]];
> 	[self replaceObjectAtIndex:b withObject:temp];
> }

I'm not sure, and I'd like a memory purist to step in and correct me if I'm
wrong, but I think this will have problems if the element in the array has a
retain count of 1.

Lifting object[a] into temp doesn't increase its retain count.
Replacing object[a] in the array should reduce its retain count by 1,
potentially deallocating it

Or am I missing something?  I think it needs to be:

- (void)swapObjectAtIndex:(unsiged)a withObjectAtIndex:(unsiged)b {
 	id temp = [[self objectAtIndex:a] retain];
 	[self replaceObjectAtIndex:a withObject:[self objectAtIndex:b]];
 	[self replaceObjectAtIndex:b withObject:temp];
	[temp release];
}

This is one of those horrible subtleties of the retain/release scheme that I
just hate.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: RE: Array of random, non-repeating numbers
      • From: "Michael Ash" <email@hidden>
  • Prev by Date: Re: Array of random, non-repeating numbers
  • Next by Date: Re: RE: Array of random, non-repeating numbers
  • Previous by thread: Re: Array of random, non-repeating numbers
  • Next by thread: Re: RE: Array of random, non-repeating numbers
  • Index(es):
    • Date
    • Thread