How to debug EXC_BAD_ACCESS in iPhone application when I can not determine the cause?

Help, I've been hacking for several weeks now! I have this application that I am developing in Simulator, and I have done a lot for the UI, it just gets to the interesting part with the data. It started right after launch, in about 90% of cases when I run it, it will throw an EXC_BAD_ACCESS exception.

I commented on all my release messages and even added some save messages to make sure that this is not what is already released. Strange, sometimes something that I do in the code will make it work, then it works until I make another change to the code. Then I comment on the new code that I added and it still crashes.

I probably read a dozen articles on the Internet about this, tried what they offer. I set breakpoints and still can't figure out where it is. When I click on the call stack in the debugger, the only place the source code is displayed is the lower level, which is the main one.

The debugger has this stack, but it hesitates every time it crashes. An inconsistent character tells me that there is some memory that it implements, but I have no idea how to find out what.

0 objc_msgSend 1 ?? 2 _CFAutoReleasePoolPop 3 -[NSAutoReleasePool release] 4 _UIApplicationHandleEvent 5 PurpleEventCallback 6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ 7 __CFRunLoopDoSource1 8 __CFRunLoopRun 9 CFRunLoopRunSpecific 10 CFRunLoopRunInMode 11 -[UIApplication _run] 12 UIApplicationMain 13 main 

A few facts:

  • I installed NSZombieEnabled that did not make changes to the console Exit
  • I used tools using the Leak Profile, it did not show any Leaks
+6
source share
2 answers

you need to include zombie objects in your code, as well as check Autoreleased objects and possibly enable debugging.

I have added three environment variables.

  • NSZombieEnabled
  • NSAutoreleaseFreedObjectCheckEnabled
  • NSDebugEnabled

they are all installed in YES

here is a link to the path i took.

http://www.codza.com/how-to-debug-exc_bad_access-on-iphone

if you are using Xcode 4, then you will add them to the Arguments section of the Edit Schemes list.

Another thing to note: you should only free or save the objects that you save. You save the save on the following objects.

  • Any object that you assign [NSObject alloc]
  • Any object obtained using a static new command [NSObject new]
  • Any object that you explicitly save [save myObject]
  • Any copy of an object [myObject copy]
  • Any property with the save or copy attribute @property (save) NSString * myProperty;

if you send auto-advertising to any object other than this, you may accidentally receive this and other errors.

Usually I release objects and then set them to zero, so if I release them later, I will not have problems, because if you autorelease nil, you will get zero.

 NSObject *myObject = [incomingObject retain]; // Do something with the object. [myObject autorelease]; [myObject autorelease]; // This line will end in an error down the line when the object is released past 0, or when the release pool is drained. myObject = nil; [myObject release]; // This line will do nothing. no error, no effect. 
+10
source

The most likely reason is adding garbage or an already freed object to the Autorelease pool - perhaps in this PurpleEventCallback function?

0
source

Source: https://habr.com/ru/post/885871/


All Articles