开发者

How to most efficiently (both memory & performance wise) load a uitableview with large number of records?

We have a web service iPhone app which fetches short texts (no graphi开发者_高级运维cs) in increment of 10 records - user can load more records by pressing 'load more' button. (akin to 'load 25 more' in default 'App Store' App)

Currently, NSXMLParser is used to parse the XML, the records are stored then in NSMutableArray, and new records (from 'load more') are appended to the array.

Now, we are experiencing two problems, which we believe are related to our current method of storing the records into the RAM. These are:

  1. In low memory conditions, when we switch back to the App from app switcher, and then press 'back' button from the detail view, App either crashes or reloads the table view!
  2. After having just 400 records loaded the app crashes!

To combat these issues, will, just storing the records into SQLite (or Core Data) instead of an array, do it? Or we need to do something more/different?

Please guide!

Thanks!


I am able to show more than 12000 records with sizable text & images in each row. I suspect you are having some other problem?

Have you profiled your code? Try Instruments. Also when you launch & come back from App switcher, how are you handling viewWillDisappear and viewDidDisappear? Are you dealloc or release something when you switch views?


  1. You should override didReceiveMemoryWarning: in your view controller if you do not want the view deallocated when a memory warning occurs. It could be due to that. As well as that, your viewDidLoad method should recreate the view state ensuring that no interface element is left deallocated or nil.
  2. If you allocate too much memory in one go, the iOS Watchdog service will kill your app because it suspects the app will cause the amount of memory allocated to reach 100% (after which, bad things happen). It's also possible that if you use the UITableView methods to add extra records onto the end of the list (insertRowsAtIndexPaths:withRowAnimation:) it could be throwing out an NSInconsistencyException under heavy and/or repeated usage. If your loading methods are asynchronous, then maybe it just wasn't ready in time or there was a network failure, and the insert call for your array didn't insert the full number of rows, which will crash the app if the number of rows doesn't match your data source method numberOfRowsInSection:.


resolved it... after reading @Steven's comment... I got convinced that it was not memory issue... so, I digged further, & found the issue.

Actually, I have a deselectRowAtIndexPath method in tableview. And in low memory environment, iPhone releases the records stored in memory... so, in that situation, deselectRowAtIndexPath was pointing to nothing, which was causing the crash... modified & resolved it now!

Thanks!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜