当我使用NSMutableDictionary时iphone应用程序崩溃

时间:2010-11-18 17:06:18

标签: iphone ios-simulator

在我的控制器中获取此代码(void)viewDidLoad方法

self.purchasesPerClassification = [NSMutableDictionary 
                                  dictionaryWithObjects:[NSArray arrayWithObjects:@"Moo",nil] 
                                  forKeys:[NSArray arrayWithObjects:@"MooKey",nil]
                                  ];

据我所知,这些都是自动释放,因为我没有使用alloc init, 在我的dealloc我有

[self.purchasesPerClassification release];

这是一个带UITableViewController的控制器的一部分,这个控制器是从一个主容器加载创建的,并添加到主控制器navigationController这似乎使我的应用程序在模拟器中崩溃,就像我在它运行的代码中没有它一样关于为什么会崩溃的任何指针

继承人.h

@interface FirstAiderInsurancePurchasesViewController : UITableViewController {

    NSArray * availableClassifications;

    NSMutableDictionary * purchasesPerClassification;

}

@property(nonatomic, retain) NSArray * availableClassifications;
@property(nonatomic, retain) NSMutableDictionary * purchasesPerClassification;

@end

并且继承了.m部分

@implementation FirstAiderInsurancePurchasesViewController
@synthesize availableClassifications;
@synthesize purchasesPerClassification;

- (void)viewDidLoad {
    [super viewDidLoad];

    self.availableClassifications = [NSMutableArray arrayWithObjects:@"Completed",@"Recover's",nil];

    self.purchasesPerClassification = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Object",nil]
                                                                          forKeys:[NSArray arrayWithObjects:@"ObjectKey",nil]];

}
- (void)dealloc {
    [super dealloc];
    self.availableClassifications = nil;
    self.purchasesPerClassification = nil;
}

我试过了两次

[purchasesPerClassification release];

以及当我回到根控制器时崩溃

2 个答案:

答案 0 :(得分:0)

首先,purchasesPerClassification的属性定义是什么?

无论如何,假设它是复制或保留,你可能想要:

self.purchasesPerClassification = nil;

[purchasesPerClassification release];

答案 1 :(得分:0)

[NSMutableDictionary dictionaryWithObjects]返回一个自动释放的实例 你还没有[self.purchasesPerClassification release];

但是[purchasesPerClassification release]