i have leaks in this code. The performane tool leaks tell me that this is in this line:
NSArray *fakeData = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FakeData" ofType:@"plist"]];
I can’t find out what is going on. The plist that i am loading have 3 NSDictionary Elements, so same as leaks in screenshot. Each Dictionary has 3 strings.
The entire code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//Ładowanie danych
if (![[FlickrFetcher sharedInstance] databaseExists]) {
NSArray *fakeData = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"FakeData" ofType:@"plist"]];
for (NSDictionary *element in fakeData) {
//Wypełnianie CoreData danymi
Photo *newPhoto = (Photo *)[NSEntityDescription insertNewObjectForEntityForName:@"Photo"
inManagedObjectContext:[[FlickrFetcher sharedInstance] managedObjectContext]];
NSLog(@"Creating Photo: %@", [element objectForKey:@"name"]);
[newPhoto setName:[element objectForKey:@"name"]];
[newPhoto setImageURL:[element objectForKey:@"path"]];
NSLog(@"Person is: %@", [element objectForKey:@"user"]);ŕŕŕ
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == %@", [element objectForKey:@"user"]];
NSMutableArray *peopleArray = (NSMutableArray *)[[FlickrFetcher sharedInstance] fetchManagedObjectsForEntity:@"Person"
withPredicate:predicate];
NSEnumerator *enumerator = [peopleArray objectEnumerator];
Person *person;
BOOL exists = FALSE;
while (person = [enumerator nextObject]) {
NSLog(@"Person is: %@", person.name);
if ([person.name isEqualToString:[element objectForKey:@"user"]]) {
exists = TRUE;
NSLog(@"-- Person exists: %@", person.name);
[newPhoto setOwner:person];
}
}
if (!exists) {
Person *newPerson = (Person *)[NSEntityDescription insertNewObjectForEntityForName:@"Person"
inManagedObjectContext:[[FlickrFetcher sharedInstance] managedObjectContext]];
[newPerson setName:[element objectForKey:@"user"]];
NSLog(@"Person created: %@", newPerson.name);
[newPhoto setOwner:newPerson];
}
NSError *error;
if (![[[FlickrFetcher sharedInstance] managedObjectContext] save:&error]) {
NSLog(@"Unresolved error %@ %@", error, [error userInfo]);
exit(-1);
}
[fakeData release];
}
}
//Person Navigation Controller
personNavigationController = [[UINavigationController alloc] init];
PersonListViewController *personListViewController = [[PersonListViewController alloc] initWithStyle:UITableViewStylePlain];
personListViewController.title = @"Contacts";
[personNavigationController pushViewController:personListViewController animated:NO];
[personListViewController release];
//Recent Photo Navigation Controller
recentPhotoNavigationController = [[UINavigationController alloc] init];
RecentPhotoViewController *recentPhotoViewController = [[RecentPhotoViewController alloc] init];
recentPhotoViewController.title = @"Recent";
UITabBarItem *item = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemRecents tag:1];
recentPhotoViewController.tabBarItem = item;
[item release];
[recentPhotoNavigationController pushViewController:recentPhotoViewController animated:NO];
[recentPhotoViewController release];
//Tab Bar Controller
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:
personNavigationController,
recentPhotoNavigationController,
nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
return YES;
}
It looks like your fakeData array is being released inside of the for loop, which seems problematic on several levels. You probably meant to release it when the loop has exited. From Leaks’ perspective, the for loop might never be entered, in which case the object would be leaked.