Jef*_*688 0 memory-management objective-c retain nsmutablearray ios
我在一个表视图控制器的dealloc中遇到了EXC_BAD_ACCESS崩溃.释放给定retain属性的NSMutableArray时发生崩溃.我有第二个NSMutableArray也被赋予了一个retain属性,但它的发布不会导致崩溃.请查看以下代码,看看我是否忽略了有关内存管理的内容.谢谢.
在我的头文件中,我有以下内容:
@interface selectSourcesTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *selectedNames;
NSMutableArray *selectedAvailability;
}
@property (retain, nonatomic) NSMutableArray *selectedNames;
@property (retain, nonatomic) NSMutableArray *selectedAvailability;
Run Code Online (Sandbox Code Playgroud)
在我的实现中,我有以下内容:
@implementation selectSourcesTableViewController
@synthesize selectedNames;
@synthesize selectedAvailability;
- (void)viewDidLoad {
NSArray *names = [selectedSourceFileContent objectForKey:@"selectedNames"];
selectedNames = [[NSMutableArray alloc] initWithObjects: nil];
NSArray *availability = [selectedSourceFileContent objectForKey:@"selectedAvailability"];
selectedAvailability = [[NSMutableArray alloc] initWithObjects: nil];
for (int i=0; i < [names count]; i++) {
NSString *aName = [names objectAtIndex:i];
[selectedNames addObject: aName];
NSString *anAvailability = [availability objectAtIndex:i];
[selectedAvailability addObject: anAvailability];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: kCellIdentifier];
...
for (int i=0; i < [selectedNames count]; i++) {
if ([contentForThisRow isEqualToString:[selectedNames objectAtIndex:i]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
}
- (void)dealloc {
[super dealloc];
[selectedNames release];
[selectedAvailability release];
}
Run Code Online (Sandbox Code Playgroud)
上面显示的代码显示了这两个数组的唯一用途.
因此,当selectedNames发布时没有任何不好的事情发生,但是当selectedAvailability被释放时,我得到了EXC_BAD_ACCESS崩溃.
最后一个观察.启动xcode后第一次运行此代码时没有崩溃.此后,每次重新运行应用程序时都会崩溃.
有什么想法吗?
归档时间: |
|
查看次数: |
625 次 |
最近记录: |