Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DarkNemesis618

macrumors newbie
Original poster
Jun 6, 2008
5
0
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?

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];
 
I don't see the problem, unfort.
I assume your properties are declared as "retain?" ( all 4 of them?)

Either way, try to NSlog the length of your array right before using it in the 2nd snippet. That'll narrow the problem - is it the array, or a problem with it's contents.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.