Completely new to Objective-C, trying to find out when I need to alloc and release objects.
For example, I want to fetch some data from the Web. I found an article at Apple which has this code:
NSURLRequest *theRequest=[NSURLRequest requestWithURL:
[NSURL URLWithString:@"http://www.apple.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc]
initWithRequest:theRequest delegate:self];
What I don't understand is: Why do they need to call alloc on the connection but not on the request? How do I know when I need alloc and when not?
Similar questions for release. From what I read, I only ever need to release objects that were initialized using alloc/init. But all "initWithXXX" functions return autoreleased objects instead.
Is this a hard rule, or just convention? Is there a way to find out if I need to release an object or not?