Re: Two Dimensional Array
Re: Two Dimensional Array
- Subject: Re: Two Dimensional Array
- From: Graff <email@hidden>
- Date: Fri, 12 Sep 2008 15:33:35 -0400
On Sep 12, 2008, at 3:24 PM, Graff wrote:
// create the 2-D array
NSArray *twoD = [NSArray arrayWithObjects:
[NSMutableArray new],
[NSMutableArray new],
[NSMutableArray new],
[NSMutableArray new], nil];
I wrote this quickly without thinking about it. The +new method is
not the correct one to use in this example because it will create an
object with a retain count of 1, which means that it will leak when
the NSArray object is released since the NSArray automatically retains
objects added to it. It's better to use the +array method as follows:
// create the 2-D array
NSArray *twoD = [NSArray arrayWithObjects:
[NSMutableArray array],
[NSMutableArray array],
[NSMutableArray array],
[NSMutableArray array], nil];
This way the NSArray gets NSMutableArray objects with a retain count
of 0 so they will be deallocated when the NSArray is deallocated and
calls release on the objects it contains.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden