I've been working with this code for a couple of days trying to determine the cause of some memory leaks. Pretty much every line after the "for loop" is generating memory leak percentages in the leak performance tool.
I've been trying a variety of permutations to get it to work.
This is the code I'm running now to try and get to the bottom of it:
-(void)populateArrays
{
NSArray *arrTempSorted;
[arrContacts removeAllObjects];
[arrZzoneContacts removeAllObjects];
[arrNormalContacts removeAllObjects];
for( int i = 0 ; i < 200 ; i++ )
{
[arrZzoneContacts addObject:[[[NSArray alloc] initWithObjects: [NSNumber numberWithInt:1], @"Composite Name", @"YES", @"first name", @"last name", @"first", nil] autorelease]];
[arrNormalContacts insertObject:[[[NSArray alloc] initWithObjects: [NSNumber numberWithInt:1], @"Composite Name", @"YES", @"first name", @"last name", @"first", nil] autorelease] atIndex:[arrNormalContacts count]];
[arrContacts addObject:[[[NSArray alloc] initWithObjects: [NSNumber numberWithInt:1], @"Composite Name", @"YES", @"first name", @"last name", @"first", nil] autorelease]];
}
arrTempSorted = [arrContacts sortedArrayUsingFunction:order context:NULL];
arrContacts = [arrTempSorted mutableCopy];
arrTempSorted = [arrZzoneContacts sortedArrayUsingFunction:order context:NULL];
arrZzoneContacts = [arrTempSorted mutableCopy];
arrTempSorted = [arrNormalContacts sortedArrayUsingFunction:order context:NULL];
arrNormalContacts = [arrTempSorted mutableCopy];
//[arrTempSorted release];
}
The arrays and function are in the appDelegate.h file. The arrays are initialized like so:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Global variables
arrContacts = [[NSMutableArray alloc] init];
arrZzoneContacts = [[NSMutableArray alloc] init];
arrNormalContacts = [[NSMutableArray alloc] init];
// Override point for customization after application launch.
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
I've tried the method of declaring an array in didFinishLaunchingWithOptions then assigning it to the arrContacts (for example) and then releasing it but I get "bad access" errors when we get to the populateArrays method.
Any insight would be greatly appreciated and please let me know if I can provide greater detail