释放 NSInitationOperation 会导致应用程序崩溃
我有以下代码
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:* 对象 0x726ed50 错误:未分配正在释放的指针 *在malloc_error_break中设置断点进行调试
我认为 NSOperationQueue 负责保留对象。我是否做错了什么或没有意识到。
Hi I have the following code
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];
when I uncomment [operation release] my app crashes. And I get this error :
malloc: * error for object 0x726ed50: pointer being freed was not allocated
* set a breakpoint in malloc_error_break to debug
I was of view that NSOperationQueue takes care of retaining objects. is there something I am doing wrong or not aware of.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Instruments 的 Zombies 模板进行调试。当您在对象应该已释放的情况下向其发送消息时,时间线中会出现一个标志;您可以单击该标志中的按钮开始调查不当释放该对象的原因。
顺便说一句,您不需要创建该字符串对象。
constructXMLMessage:
返回的字符串将持续与当前自动释放池一样长的时间,这应该是您需要使用它的所有时间。它不会突然死在你身上。Use Instruments's Zombies template to debug this. A flag will appear in the timeline when you send an object a message after it should have deallocated; you can click the button in that flag to begin investigating what unduly released the object.
By the way, you don't need to create that string object. The string that
constructXMLMessage:
returns will last as long as the current autorelease pool, which should be all the time you need to work with it. It won't suddenly die on you.