Praveen
Praveen

Reputation: 1

Sqlite database huge records fetch in my ios app

In my ios app I need to fetch around 300 000 records (select query) from sqlite database. But what is happening is in xcode simulator is took around 6GB memory and when I run in device (it took 700MB out of 1GB) than the device is getting crashed. How to best can I do to overcome this issue.

Upvotes: 0

Views: 134

Answers (2)

Mahmoud Elsheikh
Mahmoud Elsheikh

Reputation: 18

I faced the same issue while searching a big size local sqlite db on ios and I fixed it using a background extended task Apple doc also check Finite-Length Tasks form raywenderlich

Upvotes: 0

Jon Rose
Jon Rose

Reputation: 8563

As I understand it, you are trying to query 300,000 records from an SQL database at once on a mobile device and are running out of memory.

300,000 records is a lot for a mobile device. It is hard to imagine that all of those records are being displayed to the user at the same time. Usually there are 10-20 being displayed in a tableview and as the user scrolls he expects to be able to see more.

When a person first loads the page you do not need to load all the possible entities that he can scroll to. You just need to get a count. As the user scrolls you can fetch the records as you need them. For example you first do a query for the first 20, and as the user scrolls you load records 21-40, and then 41-60 etc. You can keep what you fetch in a small cache and clear them out as the user scrolls so you don't have too many in memory at one time.

It is hard to give better advice without seeing your code, but I hope this helps.

Upvotes: 3

Related Questions