angrysword
angrysword

Reputation:

Debug Iphone Program received signal: "EXC_BAD_ACCESS"

My iphone app randomly received this message. I know certain it is memory release problem. However what is the best way to find which object leads this problem. Here are what I have tried

  1. Use Instrument Leak and ObjectAllocation Trace. Dont saw any help to know which object have this problem

    1. Put NSZombieEnabled=YES and project executive ... Dont saw any help either

    2. Put NSLog everywhere but the EXE_BAD_ACCESS just appear anywhere. in the debuger, just saw the code happened in the assembly. like objc-msg send.

    3. review code many times and read memory management a lot time and research online a lot time. but no surprise.

    Is there a completed solution to figure out this problem easily. I am a previous Visual C++ programmer, I deal with memory management with years and it is easy to debug and figure out in Visual C++.

Upvotes: 1

Views: 10882

Answers (6)

zambono
zambono

Reputation: 1397

To check what the error might be

Use NSZombieEnabled.

To activate the NSZombieEnabled facility in your application:

Choose Project > Edit Active Executable to open the executable Info window. Click Arguments. Click the add (+) button in the “Variables to be set in the environment” section. Enter NSZombieEnabled in the Name column and YES in the Value column. Make sure that the checkmark for the NSZombieEnabled entry is selected.

found this on iPhoneSDK

Upvotes: 0

Mack
Mack

Reputation: 109

You will also receive the message when you don't pass enough parameters to a variable argument method. For example having a NSLog statement like this: NSLog(@"Hello %@");

Upvotes: 0

As Juan noted, the first stop is the Debugger - what does the debug window give for a stack trace when the app crashes? You should be able to see the line it crashed on... you said in a comment to one response that you saw the crash happen around the lines:

CGPDFDocumnetRef docA=CGPDFDocumentCreatWithURL(myurl);
CGPDFDocumnetRef docB=CGPDFDocumentCreatWithURL(myurl);

Are you really using the same URL object for both calls? Which line is it exactly?

It could be something around the way you make use of the CGPDFDocumentRef, you can find example code how Apple uses them in the QuartzDemo project, file "QuartzImageDrawing.m" (you can find the demo project from the developer portal or embedded in the iPhone documentation with XCode).

XCode is actually pretty powerful, but it does things differently from other IDE's.

Upvotes: 0

Juan Karam
Juan Karam

Reputation: 61

The best way to know what happend is using the xCode Debbuger, give it a try.

Upvotes: 0

Frank V
Frank V

Reputation: 25429

In addition to Erich answer, I'd want to add go backward. Start with the most recently added release and work from there.

I ran in to this and it turned out I was releasing an auto-released object that was returned from a convenience method built in to the Cocoa-Touch framework. My problem was as Erich described -- I released this auto-released object. When the system attempted to release it, the program gave the error you are describing.

Regards,
Frank

Upvotes: 0

Erich Mirabal
Erich Mirabal

Reputation: 10048

If you couldn't see any helpful debug info, I would suggest you find all the places that you are doing a release. It is most likely the case that you have released something that did not need to be released. Code would help us in tracing the issue with you.

Upvotes: 2

Related Questions