【发布时间】:2012-03-19 07:22:39
【问题描述】:
我使用了以下代码。
MainView.h:
NSString *sCopySource;
NSString *sFileSource;
// retain and copy used both for test proposes
@property (nonatomic, retain) NSString *sCopySource;
@property (nonatomic, copy) NSString *sFileSource;
MainView.m:
// Inside the first method:
sCopySource = [NSString stringWithFormat:@"%@%@", path1, filename];
sFileSource = [NSString stringWithFormat:@"%@%@", path2, filename];
// Inside the second method:
[[NSFileManager defaultManager] copyItemAtPath:sCopySource toPath:sFileSource error:&err];
并在代码的最后一行通过启用僵尸的对象sCopySource 和sFileSource 出错:
message sent to deallocated instance
为什么?标记为retain 和copy 的属性。如何解决这个问题?
非常感谢您的帮助!
附:请不要回答使用ratain 和release 方法。它们非常不方便。
【问题讨论】:
标签: iphone objective-c ios memory-management nsstring