iPhone开发 - EXC_BAD_ACCESS错误,没有堆栈跟踪 [英] iPhone Development - EXC_BAD_ACCESS error with no stack trace

查看:96
本文介绍了iPhone开发 - EXC_BAD_ACCESS错误,没有堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:我有一个表视图显示联系人。导航栏中的添加按钮用于加载数据输入的另一个视图。这个新视图在表头中有图像,每个表单元格都有一个 UITextField 或 UITextView 。当我按Cancel键时,视图弹出并释放内存。



这是我的问题:当我打开添加接口,在任何UITextField或UITextView中提供一个值,然后按取消返回到父视图,我收到一个 EXC_BAD_ACCESS 错误。当我跟踪它,添加控制器调用dealloc正确,但在 [super dealloc] 之后,当我按继续,它抛出这个错误。只是这个,没有跟踪,虽然我使用的是NSZombieEnabled。当我运行代码与仪器,我没有得到任何错误:(


解决方案

这个错误最常见的原因是什么?



每当我收到 EXC_BAD_ACCESS

的报告时, / code>错误,我的第一个建议是通过代码来确定引起它的行,然后搜索任何显式的 [object release] 调用引用该对象。逐个注释它们,以找到可能出错的位置(当然,确保对象在以后被正确释放)。



如果该行不能帮助你找出哪些对象是导致问题,请开始查看你的 [object release] 调用,并确保



这会导致关于的一个很好的一般准则,在Objective-C中发布


如果您拥有一个对象(分配或保留) 。


(如果您没有拥有它,通过使用Objective C / Cocoa / iPhone的内存管理,这也有一些好的提示。)


Here's my case: I have a table view showing contacts. Add button in the navigation bar is used to load another view for data entry. This new view has images in table header, and each table cell has either a UITextField or a UITextView. When i press Cancel, the view is popped out and memory is released.

Here's my issue: When i open the "Add" interface, provide a value in any of the UITextField or UITextView, and press "Cancel" to to go back to the parent view, i get an EXC_BAD_ACCESS error. When i trace it, the "Add Controller" calls dealloc properly, but after the [super dealloc] when i press Continue, it throws this error. Just this, no trace, although i'm using NSZombieEnabled. When i run the code with Instruments, i don't get any error :(

I hope i'm clear in explaining the issue. Any pointers? Thanks.

解决方案

The most common cause of this error is when you release an object and some other mechanism tries to access/release/dealloc it later.

Whenever I get a report of an EXC_BAD_ACCESS error, my first recommendation is to step through the code to determine which line is causing it, and then to search for any explicit [object release] calls that reference that object. Comment them out one-by-one to find where you may have gone wrong (and, of course, make sure the object is properly released later).

If the line doesn't help you figure out which object(s) is/are causing the problem, start looking through your [object release] calls, and make sure you aren't releasing objects too many times by accident, or releasing objects you don't own.

This leads to a good general guideline regarding release in Objective-C:

If you own an object (allocate or retain it), you release it. If you don't own it (came via convenience method or someone else allocated it), you don't release it.

(Via Memory Management with Objective C / Cocoa / iPhone, which also has some good tips.)

这篇关于iPhone开发 - EXC_BAD_ACCESS错误,没有堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆