NSKeyedUnarchiver unarchiveObjectWithFile:
アプリケーションデータを読み込むために使用しています。インストルメントでリークを使用して実行すると、次のようにするとリークが発生すると言われます。
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *archivePath = [[NSString alloc]initWithFormat:@"%@/Config.archive", documentsDirectory];
//Following line produces memory leak
applicationConfig = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
[archivePath release];
if( applicationConfig == nil )
{
applicationConfig = [[Config alloc]init];
}
else
{
[applicationConfig retain];
}
}
この線:
applicationConfig = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
32 バイトのメモリ リークが発生しています。applicationConfig はインスタンス変数です。私のinitWithCode関数は単純に次のことを行います:
- (id)initWithCoder:(NSCoder *)coder {
if( self = [super init] )
{
//NSMutableArray
accounts = [[coder decodeObjectForKey:@"Accounts"] retain];
//Int
activeAccount = [coder decodeIntForKey:@"ActiveAccount"];
}
return self;
}
理由の任意のアイデア
applicationConfig = [NSKeyedUnarchiver unarchiveObjectWithFile:archivePath];
リークを生成していますか?