> In an application I am debugging I found that in the init of some classes I
> would find:
> phonenumbers = [NSArray array];
> and in other classes I found this:
> connections= [[NSArray array] retain];
> This surprised me, shouldn't it always be retained?
It depends. Does the app need the array to persist beyond the scope of
the init method in question?
Quote:>> BTW, does [[NSArray alloc] init] automatically retain the object? Any idea
> where I can get more info on this?
In a nutshell: If you +alloc, -copy, or -retain, you get back an object
that needs to be released. If you use any other means to obtain an
object (such as sending +array, +stringWithFormat:, etc.) releasing it
is not your responsibility.
There are two excellent articles about this at stepwise.com: