2

I'm using insertOrThrow method to insert the data into SQLiteDatabase. Thrown Exceptions are handled manullay to make sure that the given value is inserted into db.

Exceptions like SQLiteFullException, SQLiteDiskIOException are having some description in android developer site to refer.

But for SQLiteOutOfMemoryException no description is there to refer. Does anyone knows when this SQLiteOutOfMemoryException will be thrown. If anyone knows, please share it.

uday
  • 1,348
  • 12
  • 27

2 Answers2

3

It should happen when your sqlite DB size goes beyond your heap size, SQLiteOpenHelper() will create an in-memory database if the name is null. try using largeHeap in your manifest or don't create in-memory DB

masoud vali
  • 1,528
  • 2
  • 18
  • 29
  • 1
    when you create it in memory, see this http://stackoverflow.com/questions/11657191/using-in-memory-sqlite-android – masoud vali Dec 06 '16 at 11:50
  • @masoudvali So SQLiteOutOfMemoryException will happens only for the in-memory type not for the file type database – uday Dec 06 '16 at 12:15
  • yes, and avoid storing large strings or bytearrays in your DB – masoud vali Dec 06 '16 at 12:21
  • *So SQLiteOutOfMemoryException will happens only for the in-memory type* **no** – Selvin Dec 06 '16 at 12:24
  • @Selvin no it's just one of the cases when it happens, I don't know about other cases – masoud vali Dec 06 '16 at 12:26
  • *I don't know about other cases* it doesn't makes answer yes ... obviously it may happend whenever sqlite3_malloc() or sqlite3_realloc() has failed ... and yes @psink you are right about heap ... native heap has nothing to do with Art/dalvik heap and sqlite mostly using native – Selvin Dec 06 '16 at 12:27
  • @Selvin If you know any better answer, inform us. Try helping others instead of complaining – masoud vali Dec 06 '16 at 12:29
  • Only you are complaining, I already wrote when it is thrown in the comment ... and using largeHeap is a poor man's choice – Selvin Dec 06 '16 at 12:30
1

There are some restrictions on size of the SQlite database in android. SQLiteOutOfMemoryException will arise when the database size exceed from 4 MB that I have tested on the below kitkat but on marshmellow it arise over 9 MB.It also depends on the available free space for run your application. So keep your database under the 4 MB. Always Take proper backup of your database in file and sync with your application server as per the application requirement. Never Store the images in the SQlite DB either in BLOB or in Base64 String Format.

Gautam Dev
  • 399
  • 2
  • 4
  • 1
    4MB for a in-memory DB I guess. – AxelH Dec 06 '16 at 12:04
  • Yes.For best practice always keep your under 4 MB and avoid storing large Strings . – Gautam Dev Dec 06 '16 at 12:10
  • 1
    For best practice, use a file ;) And your answer doesn't specify the storage of your database. So from what I can see, you are telling that a SQlite database can't store anything above 9MB ... – AxelH Dec 06 '16 at 12:13
  • You can use File System to store large amount of data.Write your db content with proper String delemeters for separation of the data. – Gautam Dev Dec 06 '16 at 12:21
  • Using a file to store the SQlite database ... not to create your own database. – AxelH Dec 06 '16 at 12:25
  • 1
    Another way to store large amount of data in SQlite DB is put your db file in the external storage and store data till the External Storage not fill.Enjoy. – Gautam Dev Dec 06 '16 at 12:25