Autorelease pool crashing App - iphone

My autorelease pool is crashing my app at random, what is the common cause of this problem?
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x0145ba63 objc_msgSend + 23
1 CoreFoundation 0x01210a6c CFRelease + 92
2 CoreFoundation 0x012f2e8a -[__NSArrayM dealloc] + 170
3 CoreFoundation 0x01210a6c CFRelease + 92
4 CoreFoundation 0x01235b8d _CFAutoreleasePoolPop + 237
5 Foundation 0x0005886c __NSFireDelayedPerform + 559
6 CoreFoundation 0x012dafe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
7 CoreFoundation 0x012dc594 __CFRunLoopDoTimer + 1220
8 CoreFoundation 0x01238cc9 __CFRunLoopRun + 1817
9 CoreFoundation 0x01238240 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x01238161 CFRunLoopRunInMode + 97
11 GraphicsServices 0x01c2e268 GSEventRunModal + 217
12 GraphicsServices 0x01c2e32d GSEventRun + 115
13 UIKit 0x002e842e UIApplicationMain + 1160
14 FancyAPint 0x000029e8 main + 102 (main.m:14)
15 FancyAPint 0x00002979 start + 53
I know this is because an object is being over released, am i correct in thinking an object is being released before the autorelease pool is trying to release it. Therefore the autorelease pool attempts to over release an object?

Your assessment is correct. Try running your app using the "Zombies" instrument in the simulator, or setting the NSZombieEnabled environmental variable to YES. These will both give you more information about what objects are being overreleased.

This will be because of extra memory releases. Do not release the object which is being allocated inside auto-release pool and is inited from object which has its own memory. This may the one reason behind this as i also faced this problem.

Related

EXEC_BAD_ACCESS Error [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I set up NSZombieEnabled in Xcode 4?
I am debugging an application and it throws an exec-bad-access error when performing a certain navigation function but only when i run it on a device.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0xf0000008
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x3421bf78 objc_msgSend + 16
1 UIKit 0x31d9a28c -[UIWebView webView:decidePolicyForNavigationAction:request:frame:decisionListener:] + 68
2 CoreFoundation 0x321ce7dc __invoking___ + 60
3 CoreFoundation 0x321297aa -[NSInvocation invoke] + 154
4 CoreFoundation 0x321293c8 -[NSInvocation invokeWithTarget:] + 44
5 WebKit 0x365f6e06 -[_WebSafeForwarder forwardInvocation:] + 246
6 CoreFoundation 0x321cda7c ___forwarding___ + 660
7 CoreFoundation 0x32128648 _CF_forwarding_prep_0 + 40
8 CoreFoundation 0x321ce7dc __invoking___ + 60
9 CoreFoundation 0x321297aa -[NSInvocation invoke] + 154
10 WebCore 0x358fa1ee _ZL11SendMessageP12NSInvocation + 18
11 WebCore 0x3590d6ea _ZL20HandleDelegateSourcePv + 74
12 CoreFoundation 0x3219facc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 8
13 CoreFoundation 0x3219f298 __CFRunLoopDoSources0 + 208
14 CoreFoundation 0x3219e03e __CFRunLoopRun + 646
15 CoreFoundation 0x3212149e CFRunLoopRunSpecific + 294
16 CoreFoundation 0x32121366 CFRunLoopRunInMode + 98
17 GraphicsServices 0x31278432 GSEventRunModal + 130
18 UIKit 0x31c20cce UIApplicationMain + 1074
19 Parliament 0x0007396a main (main.m:14)
20 Parliament 0x00073928 start + 32
This is the error log. Would anyone know why this is or how i could debug errors such as this since running thruogh an instrument doesnt hep
You possibly have released an object and subsequently try to access that object in your webView:decidePolicyForNavigationAction delegate method.
Enable "Zombie" detection in your debug build settings:
How do I set up NSZombieEnabled in Xcode 4?
This will help you identify if an object is not being properly retained.

Getting to the bottom of crash

I have the following crash that I can't replicate on demand but does happen enough to get noticed by the users.
This crash report has been symbolicated as well. How would you find out the cause!!! This only seems to happen on 4.1
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x9f069184
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x000027d8 objc_msgSend + 16
1 CoreFoundation 0x0007d749 ____CFXNotificationPost_old_block_invoke_1 + 45
2 libSystem.B.dylib 0x000d5984 _dispatch_call_block_and_release + 20
3 libSystem.B.dylib 0x000d66b0 _dispatch_continuation_pop + 72
4 libSystem.B.dylib 0x000d69fc _dispatch_main_queue_callback_4CF + 220
5 CoreFoundation 0x0002789b __CFRunLoopRun + 1335
6 CoreFoundation 0x00027277 CFRunLoopRunSpecific + 231
7 CoreFoundation 0x0002717f CFRunLoopRunInMode + 59
8 GraphicsServices 0x000045f3 GSEventRunModal + 115
9 GraphicsServices 0x0000469f GSEventRun + 63
10 UIKit 0x00004123 -[UIApplication _run] + 403
11 UIKit 0x0000212f UIApplicationMain + 671
12 MyApp 0x000024e3 main (main.m:17)
I have since managed to get a little more info, but not much.
2012-02-12 18:03:04.556 MyApp[462:307] (null): unrecognized selector sent to class 0x3e0a360c
2012-02-12 18:03:04.618 MyApp[462:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '(null): unrecognized selector sent to class 0x3e0a360c'
*** Call stack at first throw:
(
0 CoreFoundation 0x33506ed3 __exceptionPreprocess + 114
1 libobjc.A.dylib 0x30412811 objc_exception_throw + 24
2 CoreFoundation 0x335086ff +[NSObject(NSObject) doesNotRecognizeSelector:] + 102
3 CoreFoundation 0x334b01d9 ___forwarding___ + 508
4 CoreFoundation 0x334aff90 _CF_forwarding_prep_0 + 48
5 Foundation 0x302a86b3 _nsnote_callback + 142
6 CoreFoundation 0x334e4749 ____CFXNotificationPost_old_block_invoke_1 + 44
7 libSystem.B.dylib 0x31d05984 _dispatch_call_block_and_release + 20
8 libSystem.B.dylib 0x31d066b0 _dispatch_continuation_pop + 72
9 libSystem.B.dylib 0x31d069fc _dispatch_main_queue_callback_4CF + 220
10 CoreFoundation 0x3348e89b __CFRunLoopRun + 1334
11 CoreFoundation 0x3348e277 CFRunLoopRunSpecific + 230
12 CoreFoundation 0x3348e17f CFRunLoopRunInMode + 58
13 GraphicsServices 0x31b5e5f3 GSEventRunModal + 114
14 GraphicsServices 0x31b5e69f GSEventRun + 62
15 UIKit 0x341bd123 -[UIApplication _run] + 402
16 UIKit 0x341bb12f UIApplicationMain + 670
Now all of my addObservers are block based so I can't see why it would lead to an unrecognised selector.
This way won't help us much while Debugging crash. I found one of the best way to Debug the code for Crash. Follow the link for debugging technique:
https://cocoadev.com/DebuggingAutorelease.html
You need to analyze your Console very carefully to see actually why the Crash occurs. This helped me in almost all of the Code that are without ARC enabled.

Crash on [NSURLConnection releaseDelegate] in a function without NSURLConnections, how do I culprit?

Hullo,
I am experimenting a very vicious crash that shows up in the following way in the device logs:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x50000008
Crashed Thread: 0`
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x33b24c98 objc_msgSend + 16
1 Foundation 0x3429465a _NSURLConnectionReleaseClient + 30
2 CFNetwork 0x355ac608 ClientContextHolder<CFURLConnectionClient_V4>::forget() + 20
3 CFNetwork 0x355ac5ea URLConnectionClient::releaseClientLocked() + 34
4 CFNetwork 0x355a0e9a URLConnectionClient::processEvents() + 170
5 CFNetwork 0x355a0de2 URLConnection::multiplexerClientPerform(RunLoopMultiplexer*) + 30
6 CFNetwork 0x355a0d54 MultiplexerSource::perform() + 120
7 CFNetwork 0x355a0cd2 MultiplexerSource::_perform(void*) + 2
8 CoreFoundation 0x3039ca72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
9 CoreFoundation 0x3039e758 __CFRunLoopDoSources0 + 376
10 CoreFoundation 0x3039f4e4 __CFRunLoopRun + 224
11 CoreFoundation 0x3032febc CFRunLoopRunSpecific + 224
12 CoreFoundation 0x3032fdc4 CFRunLoopRunInMode + 52
13 GraphicsServices 0x35571418 GSEventRunModal + 108
14 GraphicsServices 0x355714c4 GSEventRun + 56
15 UIKit 0x358c7d62 -[UIApplication _run] + 398
16 UIKit 0x358c5800 UIApplicationMain + 664
17 inArrivo 0x000023ca main (main.m:14)
18 inArrivo 0x00002394 start + 32
After having enabled NSZombie I also have a crash on the compiler log of the following form:
2011-05-09 16:12:24.400 inArrivo[5019:707] * -[NSURLConnection releaseDelegate]: message sent to deallocated instance 0x5d61670
appearing on the app main with the last NSLog comeing from a function with no url connections. Also if I remove some pieces of very innocent code from that function, no crash occurs, and the same happens when I run the complete application on the simulator.
Could someone give me some hints about what I may do to locate the piece of code producing the crash? Normal debugging of course is of little help here.
Thanks,
Fabrizio Bartolomucci
The message indicates that the delegate for NSURLConnection was deallocated. I would suggest you check the delegate object to see if you are doing an extra release on it.

How to recognize errors from crash logs

My app works great when I build and debug but when I run on its own, it crashes due to some other issues.
I have one NSObject class, one UITableView class, one UIView class , one UITableViewCell class and one NSOperation class.
Does any body have similar issues or if any one can help me out.
Application Specific Information:
objc_msgSend() selector name: release
iPhone Simulator 235, iPhone OS 4.2 (iPhone/8C134)
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x01134a67 objc_msgSend + 27
1 UIKit 0x004ab1e2 -[UITableViewCell removeFromSuperview] + 167
2 UIKit 0x003249d9 -[UIView dealloc] + 340
3 UIKit 0x0032e281 -[UIScrollView dealloc] + 341
4 UIKit 0x003661ce -[UITableView dealloc] + 1085
5 Foundation 0x000698da __delayedPerformCleanup + 59
6 CoreFoundation 0x00f4bbde CFRunLoopTimerInvalidate + 446
7 CoreFoundation 0x00fb57d7 __CFRunLoopDoTimer + 1799
8 CoreFoundation 0x00f11cc9 __CFRunLoopRun + 1817
9 CoreFoundation 0x00f11240 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x00f11161 CFRunLoopRunInMode + 97
11 GraphicsServices 0x01874268 GSEventRunModal + 217
12 GraphicsServices 0x0187432d GSEventRun + 115
13 UIKit 0x002fa42e UIApplicationMain + 1160
14 Time 0x00001e08 main + 102 (main.m:14)
15 Time 0x00001d99 start + 53
This technote has the technical info on crashlogs:
http://developer.apple.com/library/mac/#technotes/tn2004/tn2123.html
However, you are having a debugging problem, not a crashlog problem.
See tips for debugging here:
http://www.cocoadev.com/index.pl?DebuggingTechniques
Interpreting crash logs takes practice. People here see this: removeFromSuperview and immediately think "Aha, a clue! this is likely a memory issue" because removeFromSuperview will remove a view then decrement it's retain count. if the retain count is already zero, then decrementing one more time may lead to a crash. Thus, they think you are over releasing your UITableViewCell
check your UITableViewCell for alloc/init, release or autorelease...

popViewControllerAnimated:YES crashes my app

My app crashes when I do [self.navigationController popViewControllerAnimated:YES].
It crashes more on Device than on Simulator. Please suggest how to fix this?
Date/Time: 2010-11-09 10:51:41.325 +0800
OS Version: iPhone OS 4.0.1 (8A306)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x0000286e objc_msgSend + 18
1 CoreFoundation 0x00002c30 -[NSObject(NSObject) release] + 24
2 libobjc.A.dylib 0x00003c1a objc_setProperty + 114
3 UIKit 0x000693d4 -[UINavigationController setDisappearingViewController:] + 24
4 UIKit 0x0007d5c0 -[UINavigationController _clearLastOperation] + 40
5 UIKit 0x0007d4b4 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 556
6 UIKit 0x0007d248 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 204
7 UIKit 0x0007d0b6 -[UINavigationTransitionView _navigationTransitionDidStop] + 450
8 UIKit 0x00059974 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184
9 UIKit 0x0005987e -[UIViewAnimationState animationDidStop:finished:] + 34
10 QuartzCore 0x000127ba run_animation_callbacks(double, void*) + 286
11 QuartzCore 0x0001265c CA::timer_callback(__CFRunLoopTimer*, void*) + 116
12 CoreFoundation 0x00071a54 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
13 CoreFoundation 0x00073ede __CFRunLoopDoTimer + 854
14 CoreFoundation 0x0007485e __CFRunLoopRun + 1082
15 CoreFoundation 0x0001d8e4 CFRunLoopRunSpecific + 224
16 CoreFoundation 0x0001d7ec CFRunLoopRunInMode + 52
17 GraphicsServices 0x000036e8 GSEventRunModal + 108
18 GraphicsServices 0x00003794 GSEventRun + 56
19 UIKit 0x000062a0 -[UIApplication _run] + 396
20 UIKit 0x00004e10 UIApplicationMain + 664
21 tenpay 0x00006124 main (main.m:13)
22 tenpay 0x00002324 start + 44
myviewcontroller = [[[MyViewController alloc]init]autorelease];
[self.navigationController pushViewController:myviewcontroller animated:YES];
[myviewcontroller release]; //This is my bug !!! I just fixed it.
This usually means you are sending a message to a released object which is a bad idea.
From the stack you can see that it is sending a release message to an object. I'd suggest that the object has already been released and thus hasa retain count of 0. Therefore a further release would be invalid.
I believe if you turn on a flag, I think it's called Zombie detection or something like that, then any message to a released object will generate a more descriptive message.
Perhaps a more experienced developer can jump in here with more details.
Yes, I believe Derek is pointing you in the right direction. Could you possibly list what kind of memory-related operations you are performing on the active controller before sending this release message (the release message is being sent implicitly when you try to pop it out). Please clarify if you are using autorelease for this controller,etc... Also it might be helpful to see what are the associated properties that you may have associated with this controller (ex: #property(nonatomic, retain, etc...)) if there are any.