4

The code at the moment reads something in the order of...

DoAnything() {
  OpenTheDatabase()
  // ... Do all the things! ...
}

However, the database object is never closed. This is worrisome.

The database is opened as follows:

var db = window.openDatabase( ... paramters ... );

No .closeDatabase function exists, or the documentation is incomplete. I thought the following might suffice:

db=null;

I see that sqlite3_close(sqlite3*) and int sqlite3_close_v2(sqlite3*) exist, but I'm unsure how to apply them in this case.

How do I close the database, and is it necessary?

4

1 回答 1

10

通常,您只有一个在应用启动时打开的数据库连接,并且无需在应用打开时关闭它。它是一个单线程、单用户应用程序,因此很多关于数据库连接的常规规则都不适用。

当应用程序关闭时,您可以依靠浏览器关闭所有内容 - 鉴于网络上的平均代码质量,浏览器必须非常擅长清理。

将 db 设置为 null 并让垃圾收集器完成它的工作可能也会起作用,但最好不要一开始就创建额外的对象。

于 2012-11-27T00:29:17.687 回答