ios 崩溃 EXC_BAD_ACCESS KERN_INVALID_ADDRESS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25683275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ios crash EXC_BAD_ACCESS KERN_INVALID_ADDRESS
提问by Sj.
MyApp works good in 98% of the time, But sometimes it shows a crash. And its so random.
MyApp 在 98% 的时间内运行良好,但有时会显示崩溃。它是如此随意。
The crash report shows the following.
崩溃报告显示以下内容。
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x3b1ae626 objc_msgSend + 5
1 Foundation 0x310e2381 _netServiceMonitorCallBack + 104
2 CFNetwork 0x302ea3b5 _QueryRecordReply(_DNSServiceRef_t*, unsigned int, unsigned int, int, char const*, unsigned short, unsigned short, unsigned short, void const*, unsigned int, void*) + 324
3 libsystem_dnssd.dylib 0x3b7289d9 handle_query_response + 168
4 libsystem_dnssd.dylib 0x3b72773f DNSServiceProcessResult + 582
5 CFNetwork 0x302ea3e5 _SocketCallBack_Mon(__CFSocket*, unsigned long, __CFData const*, void const*, void*) + 20
6 CoreFoundation 0x30691189 __CFSocketPerformV0 + 580
7 CoreFoundation 0x3068efaf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
8 CoreFoundation 0x3068e477 __CFRunLoopDoSources0 + 206
9 CoreFoundation 0x3068cc67 __CFRunLoopRun + 630
10 CoreFoundation 0x305f7729 CFRunLoopRunSpecific + 524
11 CoreFoundation 0x305f750b CFRunLoopRunInMode + 106
12 GraphicsServices 0x355336d3 GSEventRunModal + 138
13 UIKit 0x32f58871 UIApplicationMain + 1136
14 MyApp 0x0013f813 main (main.m:16)
All these look internal methods. I do experience these crashes on iPad 4 running iOS 7.1.2. How can I nail it down. All helps appreciated.
所有这些看起来都是内部方法。我确实在运行 iOS 7.1.2 的 iPad 4 上遇到过这些崩溃。我怎么能把它钉牢。所有帮助表示赞赏。
采纳答案by Indrajeet
This crash occurs due to a dangling pointer. When any variable or object is trying to access an object that's already been deallocated, this crash occurs.
发生此崩溃是由于悬空指针。当任何变量或对象试图访问一个已经被释放的对象时,就会发生这种崩溃。
回答by CodeBrew
This is an old question but the EXC_BAD_ACCESS KERN_INVALID_ADDRESS crash is not due to memory leak, but due to the attempt to access an deallocated object. Because the memory of the deallocated object is possibly now occupied by another object of different type, the last line in the crash stack might be mis-leading because it's not really part of your programmed execution path, so usually we need to look up the trace a little bit. However the stack trace posted by @Sj consists basically only of system calls so it's really hard. If this is generated in a debug session, adding an "All Exceptions" breakpoint might help generate a more informative stack trace.
这是一个老问题,但 EXC_BAD_ACCESS KERN_INVALID_ADDRESS 崩溃不是由于内存泄漏,而是由于尝试访问已释放的对象。因为释放对象的内存现在可能被另一个不同类型的对象占用,崩溃堆栈中的最后一行可能会误导,因为它不是你编程执行路径的真正一部分,所以通常我们需要查找跟踪一点点。然而,@Sj 发布的堆栈跟踪基本上只包含系统调用,所以这真的很难。如果这是在调试会话中生成的,添加“所有异常”断点可能有助于生成信息更丰富的堆栈跟踪。
回答by akaDuality
EXC_BAD_ACCESS KERN_INVALID_ADDRESS crash is not due to memory leak, but due to the attempt to access an deallocated object.
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 崩溃不是由于内存泄漏,而是由于尝试访问已释放的对象。
Example:if you used __weak typeof(self) weakSelf = self;
and object has been released before you accessing it inside block you'll got the crash. The reason —?access to wrong memory address because object was deallocated.
示例:如果__weak typeof(self) weakSelf = self;
在访问块内的对象之前使用并且对象已被释放,则会导致崩溃。原因——?访问错误的内存地址,因为对象被释放。
To prevent this use __strong typeof(self) strongSelf = self;
inside the block. Nil
value will be properly handled without crash
防止__strong typeof(self) strongSelf = self;
在块内使用这种方法。Nil
值将被正确处理而不会崩溃
Note:use this code sample for fast work.
注意:使用此代码示例进行快速工作。
#define weakify(var) __weak typeof(var) AHKWeak_##var = var;
#define strongify(var) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
__strong typeof(var) var = AHKWeak_##var; \
_Pragma("clang diagnostic pop")
Usage example:
用法示例:
weakify(self); // Remove retain cycle
[self someFunctionWithBlock:^{
strongify(self); // Make reference to address valid
}];