ios 线程 1:生成 EXC_BAD_ACCESS(代码 = 1,地址 = 0x30000008)问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12437605/
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
Thread 1 : EXC_BAD_ACCESS (Code = 1, address = 0x30000008) issue generated
提问by
I have an issue running an app on a simulator. The problem:
我在模拟器上运行应用程序时遇到问题。问题:
EXC_BAD_ACCESS occurring at objc_msgSend in Thread 1.
EXC_BAD_ACCESS 发生在线程 1 中的 objc_msgSend。
Screenshot :
截屏 :
In my Application, I have multiple ViewController
. when I click on back button of UINavigationBar
then this type of issue is generated, I can't explain my problem because all the functionality works properly.
在我的应用程序中,我有多个ViewController
. 当我单击后退按钮时UINavigationBar
会生成此类问题,我无法解释我的问题,因为所有功能都正常工作。
Example :-
例子 :-
1 - fitstVController
(work properly)
1 - fitstVController
(正常工作)
=> it have UITableView, when I click on specific row then it will go on another UIViewController (SecoundViewController)
=> 它有 UITableView,当我点击特定的行然后它会去另一个 UIViewController (SecoundViewController)
2 - SecoundViewController
(work properly)
2 - SecoundViewController
(正常工作)
=> it have UITableView and UIActionSheet. when I select button of UiActionSheet then another UIViewController (ThirdViewController) is open
=> 它有 UITableView 和 UIActionSheet。当我选择 UiActionSheet 的按钮时,另一个 UIViewController (ThirdViewController) 被打开
3 - ThirdViewController
(work properly)
3 - ThirdViewController
(正常工作)
=> it have UITableView and multiple UIPickerView. But HERE IS PROBLEM THAT I CAN'T GO BACK AT PREVIOUS UIViewController (SecoundViewController). => when i do that then EXC_BAD_ACCESS (Code = 1, address = 0x30000008)issue generated.
=> 它有 UITableView 和多个 UIPickerView。但这里的问题是我无法回到以前的 UIViewController (SecoundViewController)。=> 当我这样做时,会 生成 EXC_BAD_ACCESS(代码 = 1,地址 = 0x30000008)问题。
回答by
In short, this type of problem occurs when you release the memory assigned to an object that has been already released. Most likely, this type of issue is generated when you go back to your previous UIViewController
(or other cases).
简而言之,当您释放分配给已经释放的对象的内存时,就会出现此类问题。最有可能的是,当您回到以前UIViewController
(或其他情况)时会生成此类问题。
And also, I suggest reading the following link for a more thorough explanation:
而且,我建议阅读以下链接以获得更全面的解释:
回答by TimD
Setting an exception breakpoint means that Xcode will stop execution as soon as an exception is raised. It's not entirely foolproof, but this will usually result in the app breaking on the line of code that caused the problem.
设置异常断点意味着 Xcode 将在引发异常时立即停止执行。这并非完全万无一失,但这通常会导致应用程序在导致问题的代码行上中断。
That makes it a LOT easier to track down the source of the problem - although the stack trace is the definitive way of diagnosing issues, it's often far too detailed to be of much use (especially if like me you're not a compiler expert.)
这使得追踪问题的根源变得更加容易——尽管堆栈跟踪是诊断问题的权威方法,但它通常过于详细而没有多大用处(特别是如果像我一样你不是编译器专家。 )
To set this up, click on the Breakpoints
symbol in the Navigator panel and click the +
button at the bottom. Then select Add Exception Breakpoint
, and Objective-C
from the List of choices.
要进行设置,请单击Breakpoints
导航器面板中的符号,然后单击+
底部的按钮。然后选择Add Exception Breakpoint
,然后Objective-C
从选项列表中选择。
回答by Rob
As @TimD has rightly pointed out, you can set an exception breakpointand it will highlight the offending line of code (rather than trying to decipher the assembler or manually trying to identify where the problem is). And, as always, when diagnosing these sorts of memory issues, you should always enable zombies. Finally, especially important in non-ARC code, you should run your code through the static analyzeras many memory related problems can be identified there. You should always make sure you have zero warnings from the static analyzer as it invariably points out critical programming errors.
正如@TimD 正确指出的那样,您可以设置一个异常断点,它会突出显示有问题的代码行(而不是尝试破译汇编程序或手动尝试确定问题所在)。而且,与往常一样,在诊断此类内存问题时,您应该始终启用僵尸。最后,在非 ARC 代码中尤其重要的是,您应该通过静态分析器运行您的代码,因为在那里可以识别出许多与内存相关的问题。您应该始终确保来自静态分析器的警告为零,因为它总是指出关键的编程错误。