views:

27

answers:

1

NSFileManager has a method to do copying.

- (BOOL)copyItemAtPath:(NSString *)srcPath toPath:(NSString *)dstPath error:(NSError **)error

If an error occurs, the third parameter (NSError **) upon return will contain an NSError object describing the problem.

Question: do I need to release it?

There are some other methods, for example this one takes (NSString **),

NSPropertyListSerialization +(NSData *)dataFromPropertyList:(id)plist format:(NSPropertyListFormat)format errorDescription:(NSString **)errorString

do they follow the same memory management rules? To release or not to, that's the question.


As Anders said, the answer is "not" to release.

I got confused because the class NSPropertyListSerialization has a method

+ (NSData *)dataFromPropertyList:(id)plist format:(NSPropertyListFormat)format errorDescription:(NSString **)errorString

the document says that I should release the third argument if not nil. However it's deprecated and replaced by

+ (NSData *)dataWithPropertyList:(id)plist format:(NSPropertyListFormat)format options:(NSPropertyListWriteOptions)opt error:(NSError **)error

and the argument is (NSError **) now. No need to release as other similiar methods. So the general memory manegement rule is no need to release this kind of arguments.

+2  A: 

The returned NSError object is an autoreleased object so you shouldn't release it

The argument just tells the function where to put the returned error object (if any)

EDIT: can't spell today it seems

Anders K.