EXC_BAD_ACCESS message sent to deallocated instance, but I'm using ARC?

我与影子孤独终老i 提交于 2019-12-17 15:38:53

问题


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!


回答1:


Set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:

(gdb) info malloc-history 0x543216

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.




回答2:


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.




回答3:


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!



来源:https://stackoverflow.com/questions/7940198/exc-bad-access-message-sent-to-deallocated-instance-but-im-using-arc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!