正在关闭必要window.openDatabase打开的数据库? [英] Is closing a database opened with window.openDatabase necessary?

查看:523
本文介绍了正在关闭必要window.openDatabase打开的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在目前的code在......的顺序读的东西。

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.

打开数据库如下:

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

没有 .closeDatabase 函数存在,或文档是不完整的。我想下面的就足够了:

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

db=null;

我看到 sqlite3_close(sqlite3的*) INT sqlite3_close_v2(sqlite3的*)存在,但我不确定如何在这种情况下使用它们。

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?

推荐答案

通常你只有一个数据库连接,你的应用程序启动时打开,而且没有必要将其关闭,而应用程序是开放的。这是一个单线程,单用户的应用程序,所以很多关于数据库连接正常的规则并不适用。

Generally you only have one database connection that you open on app startup, and there is no need to close it while the app is open. It's a single threaded, single user app, so a lot of the normal rules about database connections don't apply.

在应用程序关闭了,你可以依靠浏览器关闭一切 - 给code在网络上的平均质量,浏览器必须是在清理pretty好

When the app shuts down, you can rely on the browser to close everything - given the average quality of code on the web, browsers have to be pretty good at cleanup.

设置分贝为null,让垃圾回收器做它的事可能也行,但最好不要摆在首位创建额外的对象。

Setting db to null and letting the garbage collector do its thing will probably also work, but it is better not to create the extra objects in the first place.

这篇关于正在关闭必要window.openDatabase打开的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆