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 autorelease
d 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).
精彩评论