• 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: NSMutableArray:arrayWithObjects question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableArray:arrayWithObjects question


  • Subject: Re: NSMutableArray:arrayWithObjects question
  • From: Hank Heijink <email@hidden>
  • Date: Fri, 17 Nov 2006 14:17:29 -0500

On Nov 17, 2006, at 2:00 PM, Jay Wooten wrote:

myArray = [NSMutableArray arrayWithObjects:@"One", @"Two", @"Three", nil];

This array is autoreleased when you get it from arayWithObjects. Class convenience methods generally give you autoreleased objects. Try initWithObjects instead, that will work.


Run the app. The table displays three rows of data and then the app crashes.

So I changed how I pre-load the array to this

[myArray addObject:@"One"];
[myArray addObject:@"Two"];
[myArray addObject:@"Three"];

I'm assuming before these calls there's myArray = [[NSMutableArray alloc] init]?
That's why. You're retaining the array now. If you had myArray = [NSMutableArray array] instead you would have seen the same crash.


Read the Memory Management Guide -- it's very important to understand how exactly retaining and releasing objects works.

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ index.html

Good luck!
Hank

Hank Heijink
www.hankheijink.com
email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >NSMutableArray:arrayWithObjects question (From: Jay Wooten <email@hidden>)

  • Prev by Date: Re: NSMutableArray:arrayWithObjects question
  • Next by Date: Re: Is willChangeValueForKey: always needed?
  • Previous by thread: Re: NSMutableArray:arrayWithObjects question
  • Next by thread: Re: NSMutableArray:arrayWithObjects question
  • Index(es):
    • Date
    • Thread