Ios UITableViewCell和分配问题
我想在我的UItableview中使用一个自定义的可重用UITableViewCell,它可以工作,但是,通过仪器分配测试,我发现当我离开UIViewController并多次重新输入时,内存并没有释放 以下是我尝试过的三种方法Ios UITableViewCell和分配问题,ios,uitableview,xcode-instruments,Ios,Uitableview,Xcode Instruments,我想在我的UItableview中使用一个自定义的可重用UITableViewCell,它可以工作,但是,通过仪器分配测试,我发现当我离开UIViewController并多次重新输入时,内存并没有释放 以下是我尝试过的三种方法 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // method #1 static N
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// method #1
static NSString *CellIdentifier2 = @"customClassicCell";
customClassicCell *cell = (customClassicCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"customClassicCell" owner:nil options:nil];
for(id currentObject in topLevelObjects)
{
if([currentObject isKindOfClass:[customClassicCell class]])
{
cell = (customClassicCell *)currentObject;
break;
}
}
}
return cell;
}
或
或
仪器显示了这一点(每次我进出UIviewcontroller时),这3种方法都存在同样的问题,内存没有正确释放。
我使用xcode 5.0目标5.1
我既不使用ARC也不使用故事板。有人有想法吗?如果您多次走出并重新进入视图控制器,您是否会发现每次重新创建表视图时内存都会急剧增加?我打赌你没有。一旦创建了单元格,它会一直保留在内存中,直到它被显式释放(因为您没有使用ARC);但同样,每次进入表视图时,您都在使用这些单元格(以及它们的内存)。您可以在图表上看到,我所做的唯一事情是先进入,然后退出,然后单击“标记生成”按钮。tablewview中显示了5个单元格,这只是一个示例。是否看到持久列?退出视图时视图控制器是否正在解除分配?这听起来好像不是,这意味着有些东西在不应该的时候强烈地保留着它。应该调用该视图控制器中的
dealloc
方法并使用该方法卸载所有这些分配感谢我被抢了,我没有在正确的位置查找问题,这是一个dealloc问题。
static NSString *cellIdentifier44 = @"custom44";
- (void)viewDidLoad {
[self.tbv registerNib:[UINib nibWithNibName:@"customClassicCell" bundle:nil] forCellReuseIdentifier:cellIdentifier44];
[super viewDidLoad];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// method #2
customClassicCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier44];
return cell;
}
// method3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier44];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier44] ;
}
return cell;
}