Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

memory leaks - finding reason for EXC_BAD_ACCESS - in Xcode4

I get an EXC_BAD_ACCESS error at a place that doesn't have anything to do with the root cause. I fortunately found the reason to be an array that was too small for the following statement [data getBytes:&tcpBuffer length:i];.

Now my question: I tried all these theree methods - but without success:

  1. Using NSZombiesEnabled did not change anything in the debug window printout
  2. When I set the scheme to debug and to use Leaks instrument it starts the leaks instruments but I don't see the debugger.
  3. When I just run the app in iPhone Simulator and the start Instruments separately, selecting the running app as a target (in the pop-up-menu in Instruments) it stops with an error saying something like "couldn't find the target ".

How does one find the root cause in cases like that? Keep in mind, at the end, it wasn't even a Zombie error! This error message is REALLY more confusing than helpful!

(luckily I just thought of my array, but surely, the next time this will haunt me somewhere else)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's quite likely that the place you get the EXC_BAD_ACCESS will not be related to the root cause. It could be related and could therefore offer a clue. But that's not certain.

To answer your points:

  1. NSZombiesEnabled will only have an effect if you invoke a method on an object that has been deallocated. That might not be the cause of your EXC_BAD_ACCESS.

  2. Using Instruments is separate to the debugger. If you profile in Instruments, the debugger is not active. Basically, it's a different tool.

  3. This should be ok. Check that your Build Configuration is set to "Debug" and not "Release".

Here's a great link on what causes EXC_BAD_ACCESS and how to track down the root problem:

Lou Franco's Understanding EXC_BAD_ACCESS


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...