gpt4 book ai didi

objective-c - 释放 NSInitationOperation 会导致应用程序崩溃

转载 作者:行者123 更新时间:2023-12-03 16:33:42 24 4
gpt4 key购买 nike

嗨,我有以下代码

NSString *analyticsStr = [[NSString alloc] initWithString:[self constructXMLMessage:TagObj]];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(sendAnalyticsString:)
object:analyticsStr];
[operationQueue addOperation:operation];
[analyticsStr release];
//[operation release];

当我取消注释 [操作发布] 时,我的应用程序崩溃了。我收到此错误:

malloc: * error for object 0x726ed50: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

我认为 NSOperationQueue 负责保留对象。我是否做错了什么或没有意识到什么。

最佳答案

使用 Instruments 的 Zombies 模板来调试它。当您在应该释放对象后向对象发送消息时,时间线中会出现一个标志;您可以单击该标志中的按钮开始调查不当释放该对象的原因。

顺便说一句,您不需要创建该字符串对象。 constructXMLMessage: 返回的字符串将持续与当前自动释放池一样长的时间,这应该是您需要使用它的所有时间。它不会突然死在你身上。

关于objective-c - 释放 NSInitationOperation 会导致应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4744691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com