我正在處理一個沒有ARC的舊項目。它有很多bug,代碼看起來很醜,我正在重寫它。UITableViewCell標識符無ARC泛洪內存
快速瀏覽一下我的代碼
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [self.table dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell = [self createCellWithInfo:[self.search objectAtIndex:indexPath.row]];
return cell;
}
-(UITableViewCell *)createCellWithInfo:(NSDictionary *)info{
UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@「Cell」] autorelease];
//set image for cell
//set text for cell.textlabel
//set text for cell.detailTextLabel
//create an UIButton and add to cell.content view
return cell;
}
點是在這行代碼 [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@「Cell」] autorelease]
如果我使用@"Cell"
這裏,那麼內存就會上升,當我向上滾動並連續倒在桌子上。 經過約15秒的滾動,我的iphone 5c變得滯後。
如果我將它設置爲nil
,一切都很好。
有人可以解釋這個嗎?我不是非ARC的familliar。
謝謝。
目標C來評價一個好的做法是什麼是零是:''如果不是'如果(細胞==零)' –
(細胞!)除非有充分的理由不點擊「編輯 - >轉換爲Obj-C ARC」? –
我同意@MikePollard,我敢打賭,這個應用程序泄漏比愛德華斯諾登多。 –