For 循环中的僵尸消息
我有一个 ivar,keys
,它是一个包含 50 个字符串的 NSMutableArray。当我的视图加载时,我在 Instruments 中收到僵尸消息错误,它引导我到这行代码:
for (int row = 0; row < r; row++) {
for (int column = 0; column < c; column++){
otherArray[column][row] = [[[keys objectAtIndex:0] retain] autorelease];
//^ Instruments brings me here
[keys removeObjectAtIndex:0];
}
}
我保留了该值以使其保持活动状态,以便 remove
不会导致崩溃,但仍然如此。我尝试过不保留和自动释放,但它仍然崩溃。当我有一个局部变量但没有 ivar 时,这种保留和自动释放的方法有效...
我需要一个 ivar,因为我需要在其他地方访问字符串。
谢谢
I have an ivar, keys
which is an NSMutableArray containing 50 strings. When my view loads, i am getting a zombie messaged error in Instruments, and it is directing me to this line of code:
for (int row = 0; row < r; row++) {
for (int column = 0; column < c; column++){
otherArray[column][row] = [[[keys objectAtIndex:0] retain] autorelease];
//^ Instruments brings me here
[keys removeObjectAtIndex:0];
}
}
I have retained the value to keep it alive so that the remove
will not cause a crash, but it still does. I have tried not retaining, and autoreleasing and it still crashes. This method of retaining and autoreleasing works when i have a local variable, but not an ivar...
I need an ivar because i need to access the strings elsewhere.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
合成它并在你的 dealloc 中释放它。
synthesize it and release and it in your dealloc.
已解决 - 内存管理问题 - 密钥未正确保留。
Solved -- Memory management problem - keys was not being correctly retained.