开发者

Question regarding Memory leak in Objective-C

If I assign something like

self.connection = [NSURLConnection connectionWithRequest:request delegate:self];

Now if do the following:

开发者_如何学Go

self.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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜