torgy
torgy

Reputation: 11

Is there a limit to the number of executeSql statements you can run on a single transaction using phonegap on Android?

Is there a limit to the number of executeSql statements you can run on a single transaction using phonegap on Android? I am starting a transaction (db.transaction(...)) and then looping through about 4000 products. For each product I am executing an executeSql INSERT statement (tx.executeSql(...)). All the executeSql INSERT statements seem to process fine, but once it hits the last one I get an "Out of Memory" error. The error also states that the "user failed to allow the allocation of more memory". It works completely fine on iOS and in Ripple, but Android is foobarred!

Upvotes: 1

Views: 323

Answers (1)

Brian Zitzow
Brian Zitzow

Reputation: 148

Is there a limit to the number of executeSql statements you can run on a single transaction using phonegap on Android?

As far as I know, there is no limit put on the specific usage of sqlite, phonegap, and android.

I also attempted insert transactions in a loop with about 8MB of data being inserted each iteration.

I also experienced Android running out of memory.

The solution, in my case, was to wrap the executeSql() method in an anonymous self executing function.

The original code, that caused memory overflow on Android only:

db.transaction(function(){
  customers.forEach(function(customer){
    tx.executeSql(...);
  });
});

The solution, which allowed for proper garbage collection:

db.transaction(function(){
  customers.forEach(function(customer){
    (function(){ tx.executeSql(...); })(); // <- Solution
  });
});

I have to be honest, at this moment I don't fully understand why. My guess is that the anonymous self-executing function creates a new context and that is what influences the garbage collection cycle with the behavior I (maybe we) want.

Give it a try and let us know!

Upvotes: 1

Related Questions