views:

30

answers:

1

I keep my database open for the life of the app and close it on termination. Now with iOS 4.0 multitasking, when going to the background, my app saves data but doesn't close the database. I believe this means that my app will always eventually get purged from memory without ever properly closing the database (or finalizing statements). Everything seems to work fine, but just wondering... is it ok to never close the database properly?

Thanks for any insight, Ernie

+3  A: 

I would recommend you close the database cleanly when your app transitions into the background. The reason for this is that your app can be killed by the system in order to preserve resources.

If this happens, your app doesn't get a chance to exit cleanly, and instead is sent the SIGKIL signal, halting your app immediately, regardless what state it's in.

Closing the database, finalising your statements and committing any changes will ensure that your state and data are safe when/if your app is forcibly quit.

Jasarien