问题描述:

I work on an average (~ 20k lines of code, Objective-C mixed with C++), and I am figthing to hunt down an EXC_BAD_ACCESS error.

I have tried all the common techniques (like enabling NSZombie, guard edges,etc.) So far, I have ruled out the possibility to access a released object, and the double-free error.

It seems that something writes on a memory space where it shouldn't. But, as many memory errors, it's not happening all the time, and it's not crashing always in the same place.

(Sometimes I receive the "object was modified after being freed" message).

Sometimes, the overwritten memory belongs to the allocator, and it crashes on malloc, or on free().

And, of course, some changes in the app may influence the bug's behaviour - if I try to comment out parts of the code, the error appears less often, so it's more difficult to find it.

Finally, I have been looking into using valgrind, but it seems that all those who used it worked on the simulator. but my code must run on the actual device (some code is ARM-specific)

Are there any general tips on how to debug such errors?

Note: The app involves video processing, so the amount of memory used is fairly large.

网友答案:

There are some special tools available on the XCode. You could try to use them in order to analyse your code. http://developer.apple.com/library/mac/#featuredarticles/StaticAnalysis/index.html It will produce some warning in case of invalid objects usage so it could help you to find a problem.

网友答案:

If you feel that the C++ code is causing the issue you could copy the C++ out of your iPhone project and create a Mac project. With this you could set up various stress tests. And, you should be able to use valgrind as well.

相关阅读:
Top