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 (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