EXC_BAD_ACCESS 消息发送到已释放的实例,但我正在使用 ARC?
我有一个从 SOAP Web 服务获取信息的应用程序,我想在 UITableView
中显示结果。
我有这个应用程序的先前版本,我正在创建一个新版本,以基本上清理内容并摆脱一堆已弃用且不再使用的遗留代码。
在以前的版本中,这效果很好。在新版本中,没有那么多。
基本上,当前场景返回 3 个字符串,我试图将它们用作 UITableView
中数据的基础。
我正在努力解决这个问题,因为追踪 EXC_BAD_ACCESS
错误实在是太难了!
(顺便说一句,如果有人有办法让调试体验更像 Visual Studio,我很想听听它!不知道哪一行导致了错误,而且无法查看我的代码,这真是令人沮丧崩溃时的局部变量以查看我已经在异常断点中添加了什么,但这似乎没有多大作用。)
无论如何,导致错误的行似乎是:
return [[self Libraries] count];
它发生在。 tableView:numberOfRowsInSection:
。
我收到的错误消息似乎引用了应存储在 NSMutableArray
[self Libraries]
中的字符串。
这是怎么回事?
我正在使用ARC,那么我的所有内存管理难道不应该得到正确处理吗?
我的代码中没有任何手动发布语句!
请帮我解决这个问题!
I've got an app that gets information from a SOAP web service and I want to display the results in a UITableView
.
I had a previous version of this app and I'm creating a new version to basically clean things up and get rid of a bunch of legacy code that's deprecated and no longer used.
In the previous version, this worked well. In the new version, not so much.
Basically, the current scenario is returning 3 strings that I'm trying to use as the basis for the data in my UITableView
.
I'm struggling with this issue because it's so stinkin' hard to track down EXC_BAD_ACCESS
errors!
(Parenthetically, if someone has a way to make the debug experience more like Visual Studio, I'd love to hear it! It's so frustrating to not have any idea which line caused the error, and also to not be able to look through my local variables at the time of the crash to see what's what. I've already added in the exception breakpoint, but that doesn't seem to do much.)
Anyway, the line that's causing the error APPEARS to be:
return [[self Libraries] count];
It occurs in tableView:numberOfRowsInSection:
.
The error message I get APPEARS to reference a string that should be stored in the NSMutableArray
[self Libraries]
.
What's going on here?
I'm using ARC, so shouldn't all of my memory management be correctly handled?
I don't have any manual release statements in my code ANYWHERE!
Please help me fix this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
设置NSZombieEnabled,MallocStackLogging 和 在调试器中保护 malloc。然后,当您的应用程序崩溃时,在 gdb 控制台中输入以下内容:
将 0x543216 替换为导致崩溃的对象的地址,您将获得更有用的堆栈跟踪,它应该可以帮助您查明位置代码中导致问题的确切行。
请参阅本文以获取更详细的说明。
Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:
Replace
0x543216
with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.See this article for more detailed instructions.
ARC 依赖于 Apple 标准/推荐的命名实践。检查您是否没有违反其中任何一条。
对于初学者来说,如果“
Libraries
”是一个实例,则存在命名问题。ARC relies on the Apple standard/recommended naming practices. Check that you are not violating any of them.
Just for starters, if "
Libraries
" is an instance there are are naming issues.好吧,我觉得有点傻,但我有两台生产机器。在其中一个上,我安装了 Xcode 4.2 beta 的副本以及最终的生产副本。我忘记卸载测试版副本并使用它来运行我的代码。一旦我清理了这个问题并针对最终发布的 Xcode 4.2 运行我的代码,一切又恢复正常了。
正如我上面向 Jonathan Grynspan 提到的,我确实了解 Obj-C 内存管理。由于某种原因,我得到了保留/释放/释放(由 ARC 执行),并且该错误在最终版本中得到了修复。
感谢您帮助追踪此问题!至少我得到了问题存在原因的明确答案!
OK, so I feel a little bit silly, but I've got two production machines. On one of them, I had installed a copy of Xcode 4.2 beta alongside the final, production copy. I forgot to uninstall the beta copy and was using it to run my code. As soon as I cleared that up and ran my code against the final, released Xcode 4.2, all works fine again.
As I mentioned to Jonathan Grynspan above, I DO understand Obj-C memory management. For some reason, I was getting a retain/release/release (performed by ARC), and that bug is remedied in the final version.
Thanks for the help in tracking this down! At least I got a definitive answer to WHY the problem existed!