For 循环中的僵尸消息

发布于 2024-09-24 12:06:35 字数 582 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凤舞天涯 2024-10-01 12:06:35

合成它并在你的 dealloc 中释放它。

synthesize it and release and it in your dealloc.

顾北清歌寒 2024-10-01 12:06:35

已解决 - 内存管理问题 - 密钥未正确保留。

Solved -- Memory management problem - keys was not being correctly retained.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文