If I assign something like
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
Now if do the following:
开发者_如何学Goself.connection = nil;
will this be a memory leak? If No, then why?
This won't be a memory leak. Its because of how objective c properties are implemented. I'm assuming you are using retain in your property declaration. Now when you do self.connection, the following method will be called. Since your connection is released first and then a retain operation to nil is performed which will just return nil. So no memory leak will occur.
-(void)setConnection:(NSURLConnection *)newConnection {
if (connection != newConnection) {
[connection release];
connection = [newConnection retain];
}
}
You can find details here http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html
精彩评论