Skip to content

Observed huge memory spike on transactions #2

@harees

Description

@harees

We were trying to use sqlite workers to move our transaction to worker thread. We observed that, when we use db.transcations multiple times on iOS, the memory usage shots up unprecedentaly and reached upto 350 MB for simple insert/update and a select query in the end. Here is a sample code which simulates the actual code.

`importScripts('SQLitePlugin.js');

self.addEventListener('message', function(ev) {
if (ev.data === 'go') {
var i = 0;
sqlitePlugin.openDatabase({
name: 'testdb.db'
}, function(db) {
db.executeSql("Select Max(Prime) lastItem from test_table;", [], function(res) {
var nextRow = res.rows.item(0).lastItem + 1;
do {
i++;
nextRow++;
db.transaction(function(tx) {
var next=nextRow;
tx.executeSql("Update test_table set numberdata=2 where prime=?",[next],function(tx1, res) {
self.postMessage('Rows affected: ' + res.rowsAffected);
if (res.rowsAffected == 0)
tx.executeSql("Insert into test_table (numberdata)values(2)",[],function(tx1, res) {
if (i == 100) {
db.executeSql("Select Prime,NumberData from test_table;", [], function(res) {
self.postMessage('Final data: ' + res.rows.length.toString());
});
}
});
},function(error){

                                                      self.postMessage( JSON.stringify(error));
                                                      });

                                    });

                                      }while (i < 100);
                                      });

            });
                  }
                  }); `

Am I doing any thing wrong? Is there any better usage suggestions.

screen shot 2016-04-10 at 11 56 42 pm

[testdb.db.zip](https://github.com/litehelpers/cordova-sqlite-workers-evfree/files/212943/testdb.db.zip)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions