So I’m making a very basic Twitter app (it’s actually Presence 2 from the Stanford iPhone course that’s on iTunes), when I decided I wanted to see if my application was leaking. So I ran Leaks and it found one right off the bat. But when I look at the stack trace the leak appears to happen in the main function when I call UIApplicationMain.
The image below shows the stack trace from instruments and the corresponding code in xcode. Does anyone know how I can stop this leak and why it’s happening?
alt text http://img193.imageshack.us/img193/1237/picture2fnj.png
EDIT: Ok I’ve searched and searched and got to where the problem is, but I still don’t know what’s going on. I’ve included the source for the TableViewController I’m having problems with.
The leak happens when I set the cell.text to [names objectAtIndex:indexPath.row]. Whats interesting is that it’s NSIndexPath that appears to be leaking somehow. How should I be managing memory with the objectAtIndex method?
On an unrelated topic, is editing my question post the best way to reply? Or should I have posted my code in a comment?
@implementation PersonListTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
if (self = [super initWithStyle:style])
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"TwitterUsers" ofType:@"plist"];
names = [[NSArray alloc] initWithContentsOfFile:path];
}
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 0;
//return [names count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
cell.text = [names objectAtIndex:indexPath.row];
return cell;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)table accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellAccessoryDisclosureIndicator;
}
- (void)dealloc {
[names release];
[super dealloc];
}
@end
Are you running the tools on the device or the simulator? I’ve found that memory issues can be different between the two.