views:

232

answers:

1

Hello everyone,

I'm using an UITableView with style UITableViewStyleGrouped initialized as follows:

CGRect imgFrame = CGRectMake(0, 0, 320, 650);
UITableView *myTable = [[UITableView alloc] initWithFrame:imgFrame style:UITableViewStyleGrouped];
myTable.dataSource = self;
myTable.delegate = self; //make the current object the event handler for view
[self.view addSubview:myTable];
[myTable release];

The data for the table is stored in an array dataArray. dataArray itself is a collection of arrays where each array represent a section of the table. Currently I have only one section with 100 records/rows.

When I installed the app onto my IPhone, I observed that this UITableView consumed 20 MB of iPhone memory. If I changed the table view style to UITableViewStylePlain, then it consumes only 4MB of memory.

What is wrong with "UITableViewStyleGrouped"?

Regards, prathumca.

A: 

There is nothing obviously wrong with your code. The most likely cause of your problem is the improper reuse of cells.

Check your logic in -tableview:cellForRowAtIndexPath:. I think you will find that when you have the style set to plain, you properly reuse cells but when you have it set to grouped you are creating new cells every time. The new cells pile up in memory.

TechZen
If there is problem with the Cells, then it could cause the same trouble for the style UITableViewStylePlain. Anyway I'm using reusable table cells and other optimization techniques. But the problem is still exists :-).
prathumca
It won't necessarily occur in the plain style because you don't have to check for the section before returning the row. In plain, the indexPath is always [0,rowNum]. In grouped, it's [sectionNum,rowNum]. You have to check the section before returning the row. [0,1] and [1,1] should return differently populated cells. A nesting error or something similar may be preventing you from reusing the cells. I had a similar problem sometime back. Of course, I can only suggest possible reasons without seeing the code.
TechZen
Hmmm, Do you mean that a plain table cannot have sections?
prathumca
Yes, having sections is what makes a table grouped.
TechZen
No, Plain tables can have multiple sections. http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/c/econst/UITableViewStylePlain
prathumca