nolanlawson / cordova-plugin-sqlite-2

Native SQLite database API for Cordova/PhoneGap/Ionic, modeled after WebSQL (UNMAINTAINED)
https://nolanlawson.com/2016/04/10/introducing-the-cordova-sqlite-plugin-2/
Apache License 2.0
168 stars 28 forks source link

Out of memory exception on Android #45

Closed duydao closed 7 years ago

duydao commented 7 years ago

Thanks for this plugin, we really appreciate it!

I'm getting an out of memory exception when trying to store a 14MB JSON into the database:

Throwing OutOfMemoryError "Failed to allocate a 41535454 byte allocation with 16777216 free bytes and 28MB until OOM

The same JSON loads fine on an iPhone.

at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:95)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:146)
at java.lang.StringBuilder.append(StringBuilder.java:216)
at com.nolanlawson.cordova.sqlite.SQLitePlugin.appendPluginResult(SQLitePlugin.java:256)
at com.nolanlawson.cordova.sqlite.SQLitePlugin.pluginResultsToString(SQLitePlugin.java:213)
at com.nolanlawson.cordova.sqlite.SQLitePlugin.runInBackground(SQLitePlugin.java:67)
at com.nolanlawson.cordova.sqlite.SQLitePlugin.access$000(SQLitePlugin.java:24)
at com.nolanlawson.cordova.sqlite.SQLitePlugin$1.run(SQLitePlugin.java:56)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.os.HandlerThread.run(HandlerThread.java:61)
nolanlawson commented 7 years ago

It's probably just too large of an object to store in SQLite. Note that Cordova has a limitation where all data has to be serialized into strings when sent between the WebView and the native context.

You may want to look into WebSQL or IndexedDB, or break up your JSON object into smaller pieces.

nolanlawson commented 7 years ago

Also the reason it fails in Android but not iOS is probably just due to device differences

danielehrhardt commented 6 years ago

Is there a new fix?

ganeshmogare commented 6 years ago

@nolanlawson can you put some more light on "or break up your JSON object into smaller pieces"