开发者

UITableView custom Cells, scrolling and memory management

开发者 https://www.devze.com 2023-01-26 21:48 出处:网络
So I have a table view that I am filling with custom table cells.The problem I am running into is it starts to slow down while scrolling when lots of items start filling the table.(I开发者_如何转开发

So I have a table view that I am filling with custom table cells. The problem I am running into is it starts to slow down while scrolling when lots of items start filling the table. (I开发者_如何转开发 have implemented a dynamic scroll so as the user scrolls there is a method that goes out and fetches the next x items from the server so they can scroll to their heart's content without refreshing/pressing anything.)

Now I am creating the cells from a custom template I built in IB and initialize them something like this:

 CustomCellClass *cell = (CustomCellClass *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
    cell = (CustomCellClass *)[nib objectAtIndex:0];
}

How should the memory management work in a case like this so I don't end up taking huge gobs of memory and slowing the scroll down? Any help/suggestions/insight would be greatly appreciated. Thanks!

EDIT: I have checked for memory leaks so that shouldn't be the issue.


So I discovered a deep rooted memory leak in one of my data controller classes that is used to fetch the data. THAT's what was causing the slowdown. I saw the massive memory usage going on, but instruments wasn't detecting a leak. Just goes to show nothing better then good old manual debugging. :) Thanks for the help.


if the leaks tool doesn't show anything, sometimes it can be worth using the heap shot. article on it here: http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/


The code fragment you've shown for managing table cells looks fine.

From your description, it sounds like the bottleneck is actual data retrieval from the server (web service?). Are you making the web service call(s) on the main thread or a separate thread? If you are not doing so already, perhaps you could call the web services on a separate thread and create "placeholder" cells that are refreshed later once the web service completes. This should keep the UI responsive, though you wouldn't necessarily see the data in each cell immediately (e.g., it might say "loading" or something similar until the data is available).

0

精彩评论

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