Search code examples
objective-ciosuitableviewscrollnszombie

UITableViewController Zombies On Scroll


Happy Friday. Having an interesting time debugging a zombie issue. I have a UITableView that gets its data source from an NSMutableArray loaded with Word objects. (See class below). When the app loads, all is good - the 1st 8 or 9 words display in table view as expected. However when I scroll, I am getting zombies in my Word objects, as evidenced in the debugger output "<Zombie>" as the value for the Word class instance variable values. (See screenshot). This results in a crash.

Screenshot showing zombies

TableSearch[12440:207] *** -[CFString respondsToSelector:]: message sent to deallocated instance 0x6b1fe70

Here is the Word class

//Word Class

#import "Word.h"

@implementation Word

@synthesize word;
@synthesize definition;

+ (id)wordWith:(NSString *)word Definition:(NSString *)definition
{

Word *newWord = [[[self alloc] init] autorelease];

    newWord.word = word;
    newWord.definition = definition;

   return newWord;

 }


 - (void)dealloc
 {
   [word release];
   [definition release];
   [super dealloc];
 }

 @end

I am sure this is something dumb but I cannot see where I went wrong.

I ran "Analyze" on Instruments and no issues were reported. After the crash, I ran "malloc_history 12440 0x6b1fe70" and looked at the output but not sure what to look for except for the class name of the objects that have the zombie, which I did not see.

Any help tracking this down is greatly appreciated.

Thanks!


Solution

  • Are the "word" and "definition" properties of your Word class both defined as "retain"? E.g.

    @property (nonatomic, retain) NSString *word;
    @property (nonatomic, retain) NSString *definition;
    

    If you've written them as:

    @property (nonatomic, assign) NSString *word;
    

    or just

    @property (nonatomic) NSString *word;
    

    Then it would account for your crash.