我有一个char *
,我用它来处理它,strtok
并得到我得到的每一行的副本strdup
。这char *
用作函数的参数,该函数将指针存储在 aNSMutableArray
中,其中包含NSPointerArray
. 问题是当我在 dealloc 中调用 release 时,我得到NSMutableDictionary
消息发送到已释放的实例`。所以我认为这里有一些严重的错误......这里有一些代码:
proceedDataBlock = ^(const char *data){
NSDate *date = [NSDate date];
int counter = 0;
char *temp = strdup(data);
char *cline = strtok(temp, "\n");
Table *dataList = [[Table alloc] initWithType:m.Type groups:groupings];
while(cline)
{
// do something
[myObject addString:strdup(cline)];
cline = strtok(NULL, "\n");
}
free(temp);
[callbackObj performSelectorOnMainThread:@selector(recieveDataModelsFinished:)
withObject:[dataList autorelease] waitUntilDone:YES]; }
myObject:addString
看起来像:
-(void)addString:(char *)line
{
// models is an NSMutableArray
char cGroup = line[32];
NSString *group = [NSString stringWithFormat:@"%c", cGroup];
NSPointerArray *dataArray = [self.models objectForKey:group];
[dataArray addPointer:line];
}
现在,当我释放我的对象并调用 dealloc 时:
-(void)dealloc
{
[_models release];
[_type release];
[super dealloc];
}
我的_models
字典中的每个条目都会得到消息
message send to deallocated instance
。
编辑:在这里我创建模型字典及其内容:
self.models = [NSMutableDictionary dictionaryWithCapacity:100];
if (mappings.count > 0)
{
self.groupings = [mappings retain];
for (GroupingInfo *group in self.groupings)
{
NSPointerArray *dataArray = [[NSPointerArray alloc] initWithOptions:NSPointerFunctionsCStringPersonality];
[self.models setValue:dataArray forKey:group.key];
[dataArray release];
}
}
else
{
NSPointerArray *dataArray = [[NSPointerArray alloc] initWithOptions:NSPointerFunctionsCStringPersonality];
[self.models setValue:dataArray forKey:ALLITEMS_GROUP_KEY];
[dataArray release];
}
}
EDIT2:当我在调试器中单步执行我的 dealloc 时,我只会收到此消息,然后如果我没有单步执行任何操作,我就会看到此消息(但没有发生崩溃)。