关于 EXC_BAD_ACCESS

阅读更多

简单看了下 Objective-c 的语法就开始Iphone开发了,

所以出各种奇怪问题都不奇怪。

根据官方解释 http://developer.apple.com/qa/qa2004/qa1367.html

出现 EXC_BAD_ACCESS 原因在于过度 release

而如果你程序中没有过度 release 就应该检查下 使用了类似 [NSString stringwithformat""]的函数

这种方法将会返回 autorelease 对象

 

我出现的情况就是使用了 [NSMutableArray arrayWithCapacity] 方法。该死。

 

But if you get something back from just about anything else including factory methods (e.g. [NSString stringWithFormat]) then you'll have an autorelease reference, which means it could be released at some time in the future by other code - so it is vital that if you need to keep it around beyond the immediate function that you retain it. If you don't, the memory may remain allocated while you are using it, or be released but coincidentally still valid, during your emulator testing, but is more likely to be released and show up as bad access errors when running on the device.

The best way to track these things down, and a good idea anyway (even if there are no apparent problems) is to run the app in the Instruments tool, especially with the Leaks option.

 

你可能感兴趣的:(Access,Objective-C,Apple,IDEA,UP)