を実装するカスタム オブジェクトの配列 (NSMutableArray) をアーカイブします。ファイルから保持プロパティ @property (非アトミック、保持) NSMutableArray *buddies; にロードしたら、オブジェクトのリリース カウントは 2 です (正しい、それは autorelease の 1 + プロパティの保持の 1 です) が、誰もそれをリリースせず、保持カウントが 1 になったので、私がそれをリリースすると、-[__NSArrayM 保持カウント]: メッセージが送信されました。割り当て解除されたインスタンス (1 つの保持カウントが自動解放であるためだと思います)
完全なコードは次のとおりです。
BuddieListViewController.h
#import <UIKit/UIKit.h>
#import "Buddie.h"
@interface BuddieListViewController : UITableViewController {
IBOutlet NSMutableArray *buddies;
[...]
}
[...]
@property (nonatomic, retain) NSMutableArray *buddies;
[...]
@end
BuddieListViewController.m
#import "BuddieListViewController.h"
#import "Buddie.h"
#import "PreviewViewController.h"
@implementation BuddieListViewController
@synthesize buddies;
[...]
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
[self loadFromDisk];
}
return self;
}
- (void)loadFromDisk {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *appFile = [documentsPath stringByAppendingPathComponent:@"BuddieArchive.ark"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:appFile]) {
self.buddies = [NSKeyedUnarchiver unarchiveObjectWithFile:appFile];
NSLog(@"1- buddies retain count %d (should be 2, 1 + 1autorelease)", [buddies retainCount]);
} else {
self.buddies = [NSMutableArray arrayWithCapacity:1];
}
}
[...]
- (IBAction)cancelledBuddie:(NSNotification *)notification
{
[editingBuddie release];
NSLog(@"2- buddies retain count %d (should be 2, 1 + 1autorelease)", [buddies retainCount]);
[buddies release];
[self loadFromDisk];
[self.tableView reloadData];
}
なぜこれが起こるのか誰にも分かりますか?