iOS FMDB 不需要關閉

來源:互聯網
上載者:User

標籤:

以前做了一個應用,裡面用到了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 不需要關閉

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.