Many ShinobiCharts in UITableView


I would like to have many (30) ShinobiCharts in a UITableView. 

In cellForRowAtIndexPath, I re-use the cells as shown below. However, memory-use increases when I scroll. How can avoid this increase of used memory?

static NSString *CellIdentifier = @"shinobiCell";
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //forIndexPath:indexPath];
            if (cell==nil)
                cell = [[UITableViewCell alloc]
                self.view.backgroundColor = [UIColor whiteColor];
            // prepare cell for re-use: remove all subviews
            [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            VMKChartData *chartData = [shinobiCharts_ objectAtIndex:rowNumber];
            ShinobiChart *shinobiChart = chartData.shinobiChart;
            [cell.contentView addSubview:shinobiChart];
             return cell;


Hi vomako,

We’ve successfully setup something similar in the past without any memory issues, so I’d be interested to find out why this memory isn’t being released.

The array shinobiCharts_ is the first thing that jumps out at me - does the number of charts in this array grow as you scroll? If so, this could be the problem. If not then I’m guessing something else in your app is still referencing the discarded charts.

Do you have any other code in your app that increases the retain count of the cell charts (or component of the chart)? Blocks, arrays, dictionaries and view hierarchies are often a hotspots when it comes to memory issues.

I hope the above suggestions help!  :laughing: