views:

138

answers:

2

I am working with a free app that calculates grades for norwegian high school students. The different subjects are stored in a sqlite database. Everything works fine, except for one thing: If i close the app and restart quickly (faster than, say, one second), it crashes. Also, this only happens if I close the app in specific circumstances involving selecting/checking subjects in a UITableView (the changes are immediately stored in the database). Anyway if I wait for more than one second before restarting the app, it never crashes.

The error is not traced in any way in the console window.

Instruments has found some memory leaks in my app, but they are very small (16 bytes). I presume that is not the reason for the crash (but I will try to stop the leaks). I have also tried deleting and reinstalling the app, and turning the iPod/iPhone on and off. No change...

I understand that I cannot ask anyone to find the error in the extensive code of my app. My questions to you guys are:

  1. Have any of you experienced similar errors? Related to sqlite?
  2. Do you think App store will reject the app because of this?
  3. Does anyone have any idea where to start looking for the error?

I am very thankful for any response!

+2  A: 

When you say "it crashes," what is the actual error you get in the stack on the phone? Is it an actual crash, or are you getting a "failed to launch in time error?"

On iPhone, it's possible for an app's main thread to terminate while still running background nondetached threads. In this sense, despite all the claims that you cannot run in the background, you actually can... for a few seconds. When the main thread terminates, you go back to Springboard, and eventually the OS will kill your process if it doesn't terminate on its own. Do you manage any of your sqlite work on a background thread? Do you create any nondetached threads (this generally requires pthreads, so if you don't know, you probably aren't, but sqlite might; check in Instruments).

It's possible that your last instance still has a lock on your database, and that your re-launch doesn't react well to that lock. Do you have proper error handling around your open?

Rob Napier
If you answer your own question, then others who have answered don't get notified. If you want to comment on something, use "add comment." To access your stack, open the Organizer in Xcode (Cmd-Ctrl-O), select the device, and then Crash Logs.
Rob Napier
A: 

Thanks for you in-depth answer, Rob!

I fear i cannot avoid revealing that i am very much a rookie:-) I have to admit i dont know how to access the stack on the Ipod touch(for now im testing on an ipod only). I usually read about my errors in the console panel, and nothing shows up there with these errors.

I think your explanation sounds very plausible. I do not consciously use any background threads, but i suppose sqlite might. I have tried commenting out the database action involved and that removed the crashing.

I dont know if it qualifies for "proper" error handling, but i open the database like this:

if(sqlite3_open([dbPath UTF8String], &database)==SQLITE_OK){ //select from the database and so on } else //NSLog an error message

This error message has not shown up in the console on the "crashes".

Ezop