iphone - Subclassed UITableViewCell Creates Zombie Unless Retained -


i've created uitableviewcell subclass custom nib, , using in 2 different uitableviews in app. works in 1 of tables, other table crashes when scroll vigorously. instruments identifies zombie in code (in cellforrowatindexpath):

nsstring *identifier = @"edit"; logtablecell *cell = (logtablecell*)[tableview dequeuereusablecellwithidentifier:identifier];  if (!cell) {    cell = (logtablecell*) [[[nsbundle mainbundle] loadnibnamed:@"logtablecell" owner:self options:nil] objectatindex:0];            [cell retain];       // prevents zombies! } nslog(@"%@: retaincount: %d", identifier, [cell retaincount]);  // other cell init stuff  return cell; 

notice [cell retain]; line - when it's in there, code works swimmingly. take out, , crash. nslog reports retaincount of 2, shouldn't necessary. if this:

   if ([cell retaincount] < 1) { [cell retain]; }       // not prevent zombies! 

it doesn't work. there's no alloc/init, shouldn't have autorelease or worry @ all, , i've thought cellforrowatindexpath releases cell me.

when i'm not using instruments, here's error xcode:

*** -[calayer retain]: message sent deallocated instance 0x4d8e930 

even though works [cell retain]; line, looks leak analyze (and me), i'd resolve problem. know what's going on here?

do not call retaincount

the absolute retain count useless.

([cell retaincount] < 1) cannot possibly work; retaincount can never return zero.

(yup -- loading nib in cellforrowatindexpath: blessed framework. coolio.)

your problem, then, lies elsewhere code (without retain) correct.

it still quite autorelease pool drain happening before regular event loop drain. in particular, somewhere has weak reference cell shouldn't.

if fire allocations instrument , turn on retain/release event recording, can see calls retain/release/autorelease object occur. event causes crash of obvious value.

in case, though, missing retain/release pair somewhere. @ least, fix symptoms. real problem kind of ui transition happens such contents prematurely reaped while other section of app still has dependencies on it. adding retain/release pair such lifespan of cell preserved across transition isn't fix in there may other dependencies.


Comments