【发布时间】:2014-01-31 16:02:59
【问题描述】:
当我使用仪器运行我的 iPhone 应用程序时,当我从显示模态视图控制器来回切换时,它显示实时字节在增长,但即使在使用超过 200 MB 后应用程序也不会被终止。
这里到底发生了什么?我是不是太占内存了? 顺便说一句,我正在使用带有 ARC 的 iOS 7。
下图显示了活动字节。
谢谢。
更新: 我的模态视图控制器中的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ActionCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
Action *action = self.actions[indexPath.section][indexPath.row];
cell.textLabel.text = action.title;
cell.textLabel.textColor = self.sectionColors[indexPath.section];
CustomCellBackgroundView *customCellBackgroundView = [[CustomCellBackgroundView alloc] init];
customCellBackgroundView.borderColor = self.sectionColors[indexPath.section];
customCellBackgroundView.fillColor = [self.sectionColors[indexPath.section] colorWithAlphaComponent:0];
if ([self.actions[indexPath.section] count] == 1) {
customCellBackgroundView.position = CustomCellBackgroundViewPositionSingle;
} else if (indexPath.row == 0) {
customCellBackgroundView.position = CustomCellBackgroundViewPositionTop;
} else if (indexPath.row == [self.actions[indexPath.section] count] - 1) {
customCellBackgroundView.position = CustomCellBackgroundViewPositionBottom;
} else {
customCellBackgroundView.position = CustomCellBackgroundViewPositionMiddle;
}
cell.backgroundView = customCellBackgroundView;
return cell;
}
模态视图控制器为调用模态的主视图控制器保留一个弱委托。 并且不 [self.presentedViewController dismissViewControllerAnimated:YES completion:NULL];永久释放模态视图控制器(及其所有子视图和变量)?
顺便说一句,CustomCellBackgroundView 可能不是问题,因为我有另一个模态视图控制器,它以相同的方式使用它,但不会增加内存使用量。
奇怪的是,即使使用了 200 MB,应用程序也没有被杀死,为什么会这样(不是在模拟器上运行,而是在实际 iPhone 上运行)?
【问题讨论】:
-
如果没有看到涉及的代码,这是不可能调试的。通常,当我使用 ARC 泄漏时,这是因为我使用了核心基础对象而忘记了 ARC 不处理这些。
-
也许你有一个参考周期。很可能您的模态视图控制器永远不会被释放。
-
ARC 并不意味着你有干净的内存!只要您有强变量或持有对对象的引用,它们就会保持活动状态。
-
大部分内存正被单元格背景使用,看起来...您是否正确使用出队来设置单元格?
-
ArtOfWarfare,我刚刚用一些代码更新了这个问题,向您展示了我如何使单元格出列。
标签: objective-c ios7 automatic-ref-counting