Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mraheel

macrumors regular
Original poster
Apr 18, 2009
136
0
Hi,

I'm trying to load from SQL, data of over 1000 rows! Yea, if i were working on a webserver, that would be a different ordeal.. i wouldnt worry so much..

Since my sqlite db is gonna be bundled with the app itself, i'm not sure how to proceed with this.
I've worked with the traditional methods from sqlitebooks tutorial and populated a tableView with over a 1000 rows, or even more. Ofcourse, search will be there.. I'm afraid will I be loading alot into memory? using alot of resources

But is there anything i should be doing differently inorder to keep the app safe, from memleaks, perhaps a different approach?? any alternatives?

any help is appreciated
 
Cells are populated when they appear into view via the following method:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

In your case all 1000 rows would not be generated at the same time. Personally, I would populate the data array or dictionary on a separate thread when loading the app. The method above will take care of the rest by only referencing the data as their respective rows are brought into view. Also, be sure to dequeue reusable cells.
 
The number of rows in your table isn't important. I have a table that can display 80,000 rows, based on user data.

The thing is to load your data in chunks. Can your user scroll down through 1000 rows? If not, do you have an index? Load the row data for each section as the table asks for it. Otherwise, load the data in chunks of some size like 20 or 50 rows.

Your table can only display ten or twelve rows at a time. That's all the data that has to be in memory at one time.
 
I already use NSMutableArray that gets everything from SQL

So your saying I load the data kinda dynamically as the user scrolls? And I classify the cells with an index.
It would be kinda tough for me to that. I'm guessing I need to figure out a way where if a user scrolls, the app should detect it and retrieve new cells and load it!.

amm..
 
@mraheel,

Is your method of loading everything at once in an array working or not?

In fact it should be simple to fill your array with [NSNull null], one for each row. Then when you need the data for a row check if it's been loaded or not, if not then load a chunk of rows into the array, replacing the null sentinel values. That's one way to load the data in chunks as needed.
 
@PhoneyDeveloper

the simple method i'm using is fine, working. It takes a while to load though in the simulator. But theres not gonna be any changes once it loads. So this is definitely ok. I was only looking less memory using methods.
I'll give what you said a try...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.