標籤:
以前做了一個應用,裡面用到了FMDB,進行每一次操作前,都open,完成操作後都close。因為我是參考他們以前的代碼。程式初期沒發現什麼問題,程式完成後,各種卡頓就出現了!即使我是放在新線程裡操作的。仔細檢查後發現,程式用在open 和 close上的cpu佔有率異常地高,尤其是快速控制項目進行測試時。後來我查到了下面的文章,原來,用錯了!
http://stackoverflow.com/questions/15720272/when-to-close-sqlite-database-using-fmdb
問題是:
When should you close the connection to an SQLite database (using [db close] in FMDB)?Right now I am closing it after running every batch of related queries, but should I rather close when my app closes? What are the pros/cons of doing either way?
答案是:
I‘m the guy who wrote FMDB.Keep it open unless you change your schema. That‘s the only reason to close it, and constantly re-opening it is a little hit on performance / battery life.
I don‘t do much iOS programming- so take my answer with a grain of salt. But no, I don‘t think you need to close it. If the fd is still around in SQLite, then it should all be good. I guess try it, and let us know what you find out :)
iOS FMDB 不需要關閉