While setting up a table view for my app, we go through an array of nodes adding them to a class and then adding several of these objects into an array that drives the creation of the cells. The problem is is that these class objects are leaking memory. I try releasing them at the end of the for loop, but when I do that and try to load the table view, the app crashes...what am I doing wrong?
list is a global variable for the tableviewcontroller
This is where it fails at, in the cellForRowAtIndexPath function
Code:
NSMutableArray *myArray = [NSMutableArray array];
if ([nodes count] > 0 )
{
for(NSInteger iCounter=0;iCounter<[nodes count];iCounter++)
{
MyClass classObject = [[MyClass alloc] init];
classObject.value1 = someValue1;
classObject.value2 = someValue2;
classObject.value3 = someValue3;
[myArray addObject:classObject];
[classObject release];
}
}
self.list = myArray ;
list is a global variable for the tableviewcontroller
This is where it fails at, in the cellForRowAtIndexPath function
Code:
if(cell == nil)
cell = [[[MyClassViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
((MyClassViewCell *)cell).myclass = (MyClass *)[self.list objectAtIndex:indexPath.row];