关于Objective-c内存、异常和僵尸的若干初级问题
内存问题:
使用xcode4.02自带的Instruments测试工具检测代码时发现执行同一段代码有时会查出内存泄漏,有时又查不出,这是为何?是否项目通过Instruments的检测就代表该项目绝对不会在运行时出现内存溢出,还是说Instruments只能做到静态的分析代码,指出代码编写上的明显问题?
该段随机检出内存异常的代码段如下:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSString *cellText = [NSString stringWithFormat:@"音频文件%d",(indexPath.row +1)]; //内存溢出 cell.textLabel.text = cellText; if ([cellText isEqualToString:selectText]) { cell.accessoryType = UITableViewCellAccessoryCheckmark; thisIndexPath = indexPath; } return cell; }