Is a database opened with window.openDatabase closed?

The code is currently reading something in order ...

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

However, the database object never closes. This is alarming.

The database opens as follows:

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

There is no .closeDatabase function, or the documentation is incomplete. I thought that might be enough:

 db=null; 

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

How to close the database and is it necessary?

+4
source share
1 answer

As a rule, you have only one database connection that you open when the application starts, and there is no need to close it while the application is open. This is a single-threaded single-user application, so many of the usual rules for connecting to a database do not apply.

When the application shuts down, you can rely on the browser to close everything - given the average quality of the code on the Internet, browsers should be very good at cleaning.

Setting db to null and letting the garbage collector do its job will probably work as well, but it's better not to create additional objects in the first place.

+7
source

All Articles