1

I have been testing the application on the device (iOS 5) while using Instruments and I found a couple of memory leaks.

This is the part of the code I'm being redirected to from Instruments (see the arrow for exact line):

- (UITableViewCell *)tableView:(UITableView *)tableView
                         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      CeldaUltimasFotosViewCell *cell =
          (CeldaUltimasFotosViewCell *) [self.tableView 
                 dequeueReusableCellWithIdentifier:@"CeldaUltimasFotosViewCell"];

      if (cell == nil) {
- - - - > NSArray *topLevelObjects =
                       [[NSBundle mainBundle] 
                             loadNibNamed:@"CeldaUltimasFotosViewCell"
                                    owner:nil options:nil];
          cell = [topLevelObjects objectAtIndex:0];
      }

      // Configure the cell...
      [[cell titulo] setFont:fuente_titulo];
      ...
      return cell;
}

As you can see, I have a custom cell which is loaded from a NIB file. There are three files for the cell (customCell.m, customCell.h, customCell.xib). The thing is that I don't know if I have to release something in the cell controller (which is now empty, no methods), since this is iOS 5 with ARC.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571

2 Answers2

0

Take a look at the Table View Programming and how to load cells from NIB (XIB) files.

https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1

The first thing weird is that you are storing the cell in a local variable. You should be wiring the custom cell up to a property in the class and all you call in your code is:

[[NSBundle mainBundle] loadNibNamed:@"CeldaUltimasFotosViewCell" owner:self options:nil];

Follow the code from Loading Custom Table-View Cells From Nib Files and you can't go wrong.

twilson
  • 2,062
  • 14
  • 19
  • Hi twilson, thanks for your advice. Unluckily I have been reading those documents for a while but with no succes. I went there after reading this answer here in Stackoverflow: [link](http://stackoverflow.com/questions/540345/how-do-you-load-custom-uitableviewcells-from-xib-files). Anyway, I will go through it all over again in case I missed something. If you see something weird in my code, let me know. I will post if I find the solution. Thanks again! – Matías Pacelli Feb 12 '12 at 12:12
  • I've added some more detail to the answer. – twilson Feb 12 '12 at 12:35
0

check out my answer here:

How can I recycle UITableViewCell objects created from a XIB?

you don't even need to use loadNibNamed any more on iOS5

Community
  • 1
  • 1
Tony Million
  • 4,296
  • 24
  • 24