Re: NSArray arrayWithObjects: count: method
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.