Re: Disposing NSArray
Re: Disposing NSArray
- Subject: Re: Disposing NSArray
- From: "John C. Randolph" <email@hidden>
- Date: Thu, 31 May 2001 23:44:22 -0700
On Thursday, May 31, 2001, at 04:03 PM, Youngjin Kim wrote:
What's the differerence between two?
Both array1 and array2 are locally instantiated in a method.
-(void) doSomething {
NSArray* array1;
NSArray* array2;
array1 = [[NSArray arrayWithObjects:s1,s2,s3,s4,nil] autorelease];
array2 = [[[NSArray alloc] initWithObjects:s1,s2,s3,s4,nil]
autorelease];
...
}
I'm getting signal raised with array1. but array2 work fine.
+arrayWithObjects returns an autoreleased instance. IOW, you don't need
to send it an -autorelease message yourself.
There is a convention in Cocoa, which is that you don't have to -release
or -autorelease anything unless you -retain, +alloc or -copy it.
See Malcolm Crawford's article, "Very simple rules for memory management
in Cocoa " at
http://www.stepwise.com/Articles/Technical/2001-03-11.01.html
-jcr
"Scientology is both immoral and socially obnoxious... it is
corrupt, sinister and dangerous." - Mr. Justice Latey, London 1984