I am preparing an iphone application in which I am using many transition among view controllers.
This means that there is one main menu view controller and after i press the necessary box, a modal view controller is being pushed. After this, I press an exit button and come again to the main menu and I can reenter.
The problem is that when I enter and exit my viewcontrollers many times, the application crashes and I have many object allocations in my instruments (but no leaks).
I also use many UIImageViews.
Any suggestions on what may be wrong?
Thank you very very much!
(using iphone OS 3.1.2)
Off the top of my head, there are a couple of things that might be going wrong:
You have either an over-released instance variable (EXC_BAD_ACCESS crash), or
You are using too much memory (i.e. you are not releasing any of your allocated objects) and you get a LowMemory crash.
Can you post a crash log? (If you're testing on a device, you can find out by checking the crash log in Xcode: Window->Organizer->iPhone Development(sidebar)->Crash logs.
You may be trying to access a member variable that has already been released. One way to find out where the application crashes is to click on the "Checkpoints" button in the toolbar and run the application.
When it crashes, open the Debugger window (Cmd-Shift-Y) and look for one of your methods in the stack trace. This location is usually where you're doing something wrong.
Related
I came across the scenario where in if after moving the map immediately if I tap on back icon while the map has not fully loaded
The application crashes.
What I can understand is Since the loading is still in progress and I tap back the the application releases the controller but the google map loads asynchronously in NSRUNloop (not sure). So that might be the problem not sure though.
So does anybody know what can be the issue and is there any way to solve this issue?
Please comment if more description required.
It sounds like that when you close the view, the object that is the delegate for the completed map load has been deallocated, causing the crash with a bad access.
A good way to get to the bottom of these types of crashes is to use Instruments (part of the Xcode suite to tools) and go zombie hunting.
For anyone who is still searching for the answer
What exactly happening was that map view events were getting fired even if the controller was released causing a crash in the app.
So the solution is Before setting the value of objMKMapView to nil you need to set value of objMKMapView.delegate to nil.
I have an app that keeps crashing as soon as it starts. Not sure why. I have image views and buttons in the main xib file. The main xib file is not mainwindow, it is firstview, so i changed it in the plist to the firstview. There may be something wrong with the xib file for firstview but it only has buttons and images and a view in the back. There are no warnings or errors when I run it, just Debugging Terminated when it crashes.
To Debug a crash problem, especially on a small application, do a binary search on removing functionality and adding it back in until you find the smallest thing that when removed makes the crash go away, and when added back in causes the crash. Sometimes this bottom-up search approach is easier than the top-down analytical approach to finding what is the problem. Then when you know what is causing the problem, it's generally much easier to focus on why it is causing a problem.
What's the very last change you made before your app started crashing? That's the one that caused your problem. If you made a lot of changes at once before running your app to test them, now you know what that's a Very Bad Idea (tm)... :-(
You probably want to switch it back to mainWindow, and then add the view as a subview in the app delegate did finish launching. also, you may want to set a break point on obj_c_exception_throw.
I am trying to access the UITextView delegates and have a problem
I have a UIViewController with the UITextViewDelegate protocol and a Nib containing the textView.
If I set the delegate inside viewDidLoad like "textView.delegate = self" and I touch the textView, the app crashes without logging errors.
If I start editing the textView with code like "[textView becomeFirstResponder]" all delegates get called.
When I set the delegate in the Nib creating a connection between the textView and the File's owner and deleting "textView.delegate = self" also no delegates get called.
What am I doing wrong here?
Regards,
Elias
It's not easy to help you without more description, posted code or a xib file.
You say application crashes without any logging errors - well, do you mean that there's no output in console's window ? That is normal, for an app that has crashed.
Anyway, you should be able to get the stack-trace to figure out where approximately the application has crashed. Open the debugger (⇧⌘Y), and see the position. That should give you an idea of what went wrong.
Here you can see an example of such debugger session (after EXC_BAD_CRASH):
First two lines doesn't give us much information, but later on we can see that application has crashed while loading user interface from a NIB file. Well, usually the only code that executes during such load are awakeFromNib methods - it's up to you to find a problem along those lines.
Often top of code's execution doesn't make any sense - for example you might see your ViewController method somewhere, but the top few function calls (those where the code crashed) are located in methods/classes which you never call in your code. In most cases that is a sign of wrong memory de-/allocation. What might happened is that you forgot to retain some of your objects, it has already been released, but you are still keeping reference (a pointer) to its memory. Because that memory has been in fact freed, another object took its place later on, usually some Apple's internal object you've never heard about. Later on your code tries to message your poor object but it sends a message to something completely different. BUMMER! That's how you get those crashes and strange stack traces.
To fix the kind of problem I've just described you can use Instruments and its Zombies instrument. Unfortunately you can't start Zombies from within Xcode, you need to start Instruments standalone, then choose the Zombies under iPhone Simulator/Memory, then Choose Target from the toolbar, you should see your application in there, or be able to navigate to it on filesystem.
What Zombies instrument does is that it never really frees memory after objects are deallocated. Instead, it will mutate those objects into NSZombie class. That class intercepts all calls to itself, and informs you when some code is trying to send a message to it.
This is how such Instruments session looks like (this is the same crash as seen in debugger above):
In the table you can see that we're trying to message UIScrollView that has already been deallocated. You can as well see the whole history of retain/release calls to this particular object. That way you can find a missing retain or wrong release/autorelease.
Remember - Zombies Instruments can only be used with Simulator, because there's not enough memory on the real device to keep all those memory blocks.
Hopefully I could help you with further analysis of your problem.
I have created a music application in iphone .
The App crashes if i keep on switching between the tabs while the song is playing.
How can i solve this problem .Please anybody help me regarding this problem
Generally such kind of issues are memory related.......just check whether ur releasing the objects at proper place or not..
Other u can put some code snippet to have a look so that we can know actually what's happening with your code..
A common cause for crashes when something repetitive happens (eg switching between tabs, screens etc) is memory problems. Make sure you are releasing the correct objects in the right place. It could very well be that every switch you are allocating objects - without freeing them when switching again. This will eventually consume your memory and crash the application.
My application brings up a different view each time it is built in Xcode. This is exactly what I want it to do. However, if I simply press the back to menu button in the simulator and then reopen it the view does not change. I am changing the view by overwriting the viewDidLoad function in a Custom View Controller. Why is it that ViewDidLoad is not called every time I click on the icon? Will that mean that on a real iphone it also will not be?
Thanks,
Sam
When you press the menu button in the simulator (or the actual iPhone) the OS, basically, stops running your app. However, it doesn't necessarily terminate the app; if you reopen the app before the OS has decided to terminate it, you will find yourself in the same state you were before. Since the app isn't reloaded, viewDidLoad isn't called.
However, viewWillAppear should still be called each time, I believe, and this might be a better place to put your code that changes how things look. Edit: A quick test shows that this isn't the case. I'll poke around and see if I can find another notification mechanism.