What happens if a UITableViewCell is not released?
What will happen if the autorelease is removed fro开发者_如何学编程m cell creation in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
STVCell *cell = (STVCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[STVCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
}
It will lead to a memory leak.
Because you call alloc
, you are responsible for also calling release
(or in this case autorelease
).
The UITableView will automatically retain the cell and release its use of the cell at the appropriate time, but unless your code also releases the reference that it holds, the cell can never be deallocated.
Nothing. And that's a bad thing: The cell will never be released and become a memory leak.
精彩评论