NSRunloop runUntilDate 导致应用程序崩溃

发布于 2024-12-10 13:07:29 字数 1258 浏览 0 评论 0原文

我有一个应用程序在 Snow Leopard 服务器上运行数天或数周。 它使用 -[NSRunLoop runUntilDate:] “暂停”十秒钟,执行其任务,然后再次暂停。运行一个多小时后,我的应用程序崩溃并显示以下报告:

崩溃报告

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000013
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Application Specific Information:
objc_msgSend() selector name: release

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff84cfef0c objc_msgSend + 40
1   com.apple.CoreFoundation        0x00007fff84e363d1 __CFRunLoopDoSources0 + 1361
2   com.apple.CoreFoundation        0x00007fff84e345c9 __CFRunLoopRun + 873
3   com.apple.CoreFoundation        0x00007fff84e33d8f CFRunLoopRunSpecific + 575
4   com.apple.Foundation            0x00007fff83e73b74 -[NSRunLoop(NSRunLoop)  runMode:beforeDate:] + 270
5   com.apple.Foundation            0x00007fff83ebf19a -[NSRunLoop(NSRunLoop) runUntilDate:] + 78

乍一看,我认为我的 NSRunLoop 对象不再有效,因此 release CF 深处的 消息会导致崩溃。但是,我认为情况并非如此 我在之前的行中获取了对 currentRunLoop 对象的引用。

崩溃时间在 1 到 1.5 小时之间变化,但我无法掌握导致崩溃的原因。 任何评论或意见或调试想法将不胜感激,因为我不知道下一步该做什么。

编辑:问题解决 - 请参阅下面我的答案

I have an application which runs for days and weeks on a Snow Leopard server.
It uses -[NSRunLoop runUntilDate:] to "pause" for ten seconds, perform its task and then pause again. After running for over one hour, my app crashes with the following report:

Crash Report

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000013
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Application Specific Information:
objc_msgSend() selector name: release

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libobjc.A.dylib                 0x00007fff84cfef0c objc_msgSend + 40
1   com.apple.CoreFoundation        0x00007fff84e363d1 __CFRunLoopDoSources0 + 1361
2   com.apple.CoreFoundation        0x00007fff84e345c9 __CFRunLoopRun + 873
3   com.apple.CoreFoundation        0x00007fff84e33d8f CFRunLoopRunSpecific + 575
4   com.apple.Foundation            0x00007fff83e73b74 -[NSRunLoop(NSRunLoop)  runMode:beforeDate:] + 270
5   com.apple.Foundation            0x00007fff83ebf19a -[NSRunLoop(NSRunLoop) runUntilDate:] + 78

At first glance I thought my NSRunLoop object is no longer valid and therefore the release message deep within CF causes a crash. However, I don't think that's the case as
I obtain the reference to the currentRunLoop object in the line before.

The crash time varies between 1 and 1.5hrs but I can't get a handle on what's causing it.
Any comments or opinions or debugging ideas would be greatly appreciated as I'm not sure what to do next.

EDIT: problem solve - please see my answer below

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

把回忆走一遍 2024-12-17 13:07:29

进一步的测试使我能够回答我自己的问题:

运行循环没有任何问题。运行循环负责释放自动释放池中的对象,这就是为什么代码任何部分的问题都可能与运行循环相关。

就我而言,我有一个没有正确清理的物体。一般情况下这个问题会在内存泄漏测试时出现。然而,这个特殊问题仅在实际的客户端安装中出现,当时 SMTP 服务器返回意外错误消息,导致对象被“遗留”,并且当运行循环最终尝试清理它时,它突然停止了。

简短回答

运行循环中的崩溃可能是由代码中的任何对象引起的。尝试重新创建问题场景并测试内存泄漏以找到违规者。

Further tests have enabled me to answer my own question:

There is nothing wrong with the run loop. It is the run loop that handles that releases objects in the autorelease pool and that's why problems from any part of the code can show to be related to the Run Loop.

In my case, I had a object that wasn't cleaned up properly. Under normal circumstances this problem would have shown up during memory leak testing. However, this particular issue only arose on the actual client installation when an SMTP server returned an unexpected error message which caused an object to be "left over" and when the run loop eventually tried to clean it up, it came to a grinding halt.

The Short Answer

Crashes in the run loop can be caused by any object in the code. Try to re-create the problem scenario and test for memory leaks to find the offender.

她如夕阳 2024-12-17 13:07:29

我知道这并不能准确回答你的问题,但是......

我不确定这是否是一个选项,因为没有示例代码,但是你考虑过 NSTimer 吗?它们非常易于使用,每 n 秒执行一次代码。

self.myTimer = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(timerTarget:) userInfo:nil repeats:YES];

其中 myTimer 是您的类的 NSTimer 属性。

当你完成后,不想再打电话了。

[self.myTimer invalidate];
self.myTimer = nil;

I know this doesn't precisely answer your question, but...

I'm not sure if this is an option, since there is no sample code, but have you considered an NSTimer? They're very easy to use to execute code every n seconds.

self.myTimer = [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(timerTarget:) userInfo:nil repeats:YES];

where myTimer is a NSTimer property of your class.

when your done, and want no more calls.

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