• 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: Two Dimensional Array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Two Dimensional Array (From: Graff <email@hidden>)

  • Prev by Date: Transparent Background for a Progress Indicator (NSView)
  • Next by Date: Re: Newb: Targeting an instance of a class instantiated by a NIB file
  • Previous by thread: Re: Two Dimensional Array
  • Next by thread: Using NSAlert with PyObjc - basics
  • Index(es):
    • Date
    • Thread