码迷,mamicode.com
首页 > 移动开发 > 详细

iOS FMDB 不需要关闭

时间:2016-02-05 18:55:52      阅读:394      评论:0      收藏:0      [点我收藏+]

标签:

以前做了一个应用,里面用到了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?

答案是:

Im the guy who wrote FMDB.

Keep it open unless you change your schema. Thats the only reason to close it, and constantly re-opening it is a little hit on performance / battery life.

 

 

I dont do much iOS programming- so take my answer with a grain of salt. But no, I dont 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 不需要关闭

标签:

原文地址:http://www.cnblogs.com/breezemist/p/5183125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!