Note that there are some explanatory texts on larger screens.

plurals
  1. POShould I release the NSError object of NSFileManager's copyItemAtPath:toPath:error:?
    primarykey
    data
    text
    <p>NSFileManager has a method to do copying.</p> <pre><code>- (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error </code></pre> <p>If an error occurs, the third parameter <strong>(NSError **)</strong> upon return will contain an NSError object describing the problem.</p> <p><strong>Question: do I need to release it?</strong></p> <p>There are some other methods, for example this one takes <strong>(NSString **)</strong>,</p> <pre><code>NSPropertyListSerialization +(NSData *)dataFromPropertyList:(id)plist format:(NSPropertyListFormat)format errorDescription:(NSString **)errorString </code></pre> <p>do they follow the same memory management rules? To release or not to, that's the question.</p> <p>---Answer</p> <p>As Anders said, the answer is "not" to release.</p> <p>I got confused because the class NSPropertyListSerialization has a method</p> <pre><code>+ (NSData *)dataFromPropertyList:(id)plist format:(NSPropertyListFormat)format errorDescription:(NSString **)errorString </code></pre> <p>the document says that I should release the third argument if not nil. However it's deprecated and replaced by </p> <pre><code>+ (NSData *)dataWithPropertyList:(id)plist format:(NSPropertyListFormat)format options:(NSPropertyListWriteOptions)opt error:(NSError **)error </code></pre> <p>and the argument is <strong>(NSError **)</strong> now. No need to release as other similiar methods. So the general memory manegement rule is no need to release this kind of arguments.</p> <p>---Reference document</p> <p>In Apple's <a href="https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html" rel="nofollow noreferrer">Advanced Memory Management Programming Guide</a>, section You Don’t Own Objects Returned by Reference:</p> <p>When you invoke any of these methods, you do not create the NSError object, so you do not own it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload