简单看了下 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.
本文探讨了Objective-C中常见的内存管理问题——EXC_BAD_ACCESS错误的原因及解决办法。通过实例分析了autorelease对象的不当使用导致的问题,并给出了跟踪此类问题的方法。
2566

被折叠的 条评论
为什么被折叠?



