0

星期五快乐。有一个有趣的时间调试一个僵尸问题。我有一个从加载的对象UITableView中获取其数据源的方法。(见下面的课程)。当应用程序加载时,一切都很好 - 第一个 8 或 9 个单词按预期显示在表格视图中。但是,当我滚动时,我的对象中出现了僵尸,正如调试器输出“<Zombie>”作为类实例变量值的值所证明的那样。(见截图)。这会导致崩溃。NSMutableArrayWordWordWord

显示僵尸的屏幕截图

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

这是Word类

//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

我确信这是愚蠢的,但我看不出我哪里出错了。

我在 Instruments 上运行了“Analyze”,没有报告任何问题。崩溃后,我运行了“malloc_history 12440 0x6b1fe70”并查看了输出,但不知道要查找什么,除了具有僵尸的对象的类名,我没有看到。

非常感谢任何跟踪此问题的帮助。

谢谢!

4

1 回答 1

1

Word 类的“单词”和“定义”属性是否都定义为“保留”?例如

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

如果你把它们写成:

@property (nonatomic, assign) NSString *word;

要不就

@property (nonatomic) NSString *word;

然后它会解释你的崩溃。

于 2012-02-03T14:45:08.157 回答