开发者

NSData initWithContentsOfURL: does not return the original allocation?

In开发者_Python百科 the documentation of NSData's initWithContentsOfURL:, it says:

The returned object might be different than the original receiver.

What are the implications of that? It seems to imply that a standard "alloc/init" line could leak memory.


there are several reasons why - class clusters being the most publicly recognized:

- (id)initWithContentsOfURL:(NSURL *)url
{
    self = [super init];
    if (self != nil) {
        NSData * result =
           [[NSDataClassClusterSpecialization alloc] initWithContentsOfURL:url];
        [self release];
        return result;
    }
    return self;
}

no leaks are introduced using this form.

it just means that you should only use the result of the alloc+init call (rather than holding onto the result of alloc), which is a good idea in any case -- even when not explicitly documented.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜