• 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: NSArray arrayWithObjects: count: method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArray arrayWithObjects: count: method


  • Subject: Re: NSArray arrayWithObjects: count: method
  • From: Ben Dougall <email@hidden>
  • Date: Sun, 13 Apr 2003 18:06:33 +0100

It crashed right from the get-go when I set them to autorelease. If NSArray isn't copying them, why would I set these things to autorelease? Would not NSArray become responsible for them once I put them in said NSArray?

i think you set them to autorelease here to temporary retain them in order to pass them to the array. the array retains the objects, and the original retains, which were autorelease retains, cease. the objects in the array end up being retained by the array, each with a retain count of 1. you need to use autorelease retainment for the intermediate passing part. - i think that's how it is.






On Sunday, April 13, 2003, at 12:49 AM, Sherm Pendley wrote:
MacdobModule *module[10];

for(i = 0; I <10; ++i)
module[i] = [[MacdobModule alloc] init]; // init a module object

modules = [NSArray arrayWithObjects: module count:10]; // create an array of 10 of them

That looks right.

Another way to do it is to avoid the C array entirely, by using an NSMutableArray:

modules = [NSMutableArray arrayWithCapacity: 10];
for(i=0; i<10; i++)
[modules insertObject: [[MacdobModule alloc] init] atIndex: i];

sherm--

I'll be trying that shortly...here I was, trying to get all the performance benefits of an immutable array :(
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: NSArray arrayWithObjects: count: method (From: Dave Sopchak <email@hidden>)

  • Prev by Date: Elaine Lee/SWD/RDC/MII/MICROTEK is out of the office.
  • Next by Date: irrelevant ADB trivia [was Re: 10.2.5 problem]
  • Previous by thread: Re: NSArray arrayWithObjects: count: method
  • Next by thread: Re: NSArray arrayWithObjects: count: method
  • Index(es):
    • Date
    • Thread