开发者

Should I release NSData dataWithContentsOfURL?

Question on memory mgmt of the following:

NSData *returnData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]                                                options:0                                    开发者_JAVA百科                 error:&err];

We are seeing our allocations spike here, but not sure if I should be releasing this memory after I have moved it off.

I get an exception when I try to release, so not understanding something about the internals here.

Thanks in advance!


No. It is returned autoreleased per naming convention.

You might check the memory management programming guide: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html


No, you don't need to release it. The dataWithContentsOfURL: method returns an autorelease object. It will be release automatically if you do not explicitly retain it.

Automatically, that is, so long as your current thread has an NSAutoreleasePool properly set up for it. All autorelease objects are released when their enclosing NSAutoreleasePool is drained. If you have found a leak in this code, then perhaps the corresponding pool is not being drained frequently enough (or perhaps not at all).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜