+1  A: 

EXC_BAD_ACCESS is a hard error. It isn't an exception and you can't catch it.

It means your code has done something that tried to access memory that isn't valid. Most likely, by trying to dereference a pointer that is trashed. Over releases are a common way to achieve this kind of crash.

In this case, the cause of the crash is most likely because you are beating upon the user interface objects from a background thread. Nothing is thread safe unless the documentation explicitly says it is thread safe and, even then, there may be limits as to what you can do from a thread.

Given the fatality of the lack of a proper threading model, I didn't look terribly closely at the rest of the code. However, there were some obvious glaring problems with memory management; leaks and a likely over-release or two.

My recommendation would be to rewrite this code entirely. Start by considering how to break up the problem along Model-View-Controller [MVC] lines. Consider whether you can use the NSURL* and NSHTTP* classes to do the client/server communication -- if you can, they can be configured to do communications asynchronously.

As far as threading is concerned, you need to very carefully consider how to divide the problem up; how to move the bits off of the main thread while not performing thread-unsafe actions upon the main thread.

bbum
Our application generally crashes after the last log of function without any wrong variable value. I am calling these functions in a timer (after every 25 secs).Crashing occurs spontaneously ie. it may crash after 1 hr or may crash after 15 min. If we use breakpoint to debug,application stops after every 25 secs :(Reg:asynchronous communication, For this we have to use delegate method of NSURLConnectionbut we need its output for next bit of codeas we need NSData as return from that function.. Is there any method by which we can execute next bit of code after the delegates call
Amit Battan
Can't say this strongly enough: Stop trying to fix the symptoms and fix the problem. This code, as written, is wrong; dozens of bugs, but more importantly, the structure is flawed. You need to take a step back and understand how to properly structure Cocoa applications before tackling this problem.
bbum
A: 

try Matt Gallaghers inspirational uncaughtexceptionhandler. http://cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html

johndpope