我正指着行“NSDictionary *dw = [NSDictionary dictionaryWithContentsOfFile:path];
”内存泄漏使用下面的代码的NSDictionary财产
NSDictionary *_allData;
@property (nonatomic, retain) NSDictionary *allData;
@synthesize allData = _allData;
+ (NSString*)getNSPath
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"alarm.plist"];
return path;
}
- (NSDictionary *)allData
{
NSString *path = [saveAlarm getNSPath];
NSDictionary *dw = [NSDictionary dictionaryWithContentsOfFile:path];
_allData = [NSDictionary dictionaryWithDictionary:dw];
return _allData;
}
的数据在plist中不断变化的,当我问要检索的是新出现的财产则泄漏。 任何建议如何清楚?或者如何实现这种没有泄漏的事情?
谢谢
此解决方案在添加了保留的行上使内存泄漏864字节。不知道为什么我应该保留它,当它是类方法。 – Vanya 2010-10-05 10:41:07
啊。当你通过API边界返回一个对象时,你需要将它作为自动发布来返回。我会更新代码。 – 2010-10-05 10:43:17
您需要保留它,因为您正在将它存储在ivar中。否则,该对象将被释放,而你的伊娃仍然有一个引用它。 – 2010-10-05 10:49:27