I've pounded my head against my monitor for hours (and read similar posts). I'm still stumped.
I declare an array in my *.h file that will display data in a table view:
@interface TeamsTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
NSMutableArray *teamsArray;
}
I allocate the array in viewDidLoad and release it in dealloc:
-(void)viewDidLoad
{
[super viewDidLoad];
// Inititalize the mutablearray that will store the xml for the table.
teamsArray = [[NSMutableArray alloc] init];
}
-(void)dealloc
{
[teamsArray release];
[super dealloc];
}
Each time viewWillAppear, I call my loadData to reload the data (because the data can change). For this post (and as I try to locate my leak), I've hardcoded the data. The comment shows the location of the reported leaks. (The leak occurs when the table view is redisplayed.)
-(void)loadData
{
// Empty any objects that are already in the array.
[teamsArray removeAllObjects];
// Fill a dictionary (normally looping through a file, but hardcoded for leak hunting).
NSMutableDictionary *oneTeamDictionary = [NSMutableDictionary dictionary];
[oneTeamDictionary setObject:@"100" forKey:@"basenumber"];
[oneTeamDictionary setObject:@"Team Name" forKey:@"teamname"];
[oneTeamDictionary setObject:@"XYZ" forKey:@"teamabbr"];
[oneTeamDictionary setObject:@"USA" forKey:@"countryabbr"];
[oneTeamDictionary setObject:@"Joe" forKey:@"manager"];
// Add this team to the array used to display table data.
[teamsArray addObject:[oneTeamDictionary copy]]; // Leaks Malloc 32 bytes and _NSCFDictionary 48 bytes here.
// Reload the table view with new data.
[self.tableView reloadData];
}
In my newbieistic state, I'd think that [teamsArray release] would free the dictionary object. I've also tried using "alloc] init]" to create the dictionary, as well as releasing and reallocating the teamsArray (rather than calling removeAllObjects). Thanks for your help!