J'ai les codes suivants, qui ont des fuites de mémoire sur l'appareil, pourriez-vous nous aider à le vérifier? Merci.self.tableView.delegate = self et self.table.dataSource = fuite auto-mémoire
@interface NewsListViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> {
@private
UITableView *tableView;
NSFetchedResultsController *fetchedResultsController;
......
}
@property (nonatomic, retain, readonly) NSFetchedResultsController *fetchedResultsController;
@end
@implementation NewsListViewController {
......
- (void)dealloc {
[fetchedResultsController release];
fetchedResultsController = nil;
tableView.delegate = nil;
tableView.dataSource = nil;
[tableView release];
tableView = nil;
[super dealloc];
}
-(void)viewDidLoad {
......
tableView.delegate = self; // **leak here**
tableView.dataSource = self; // **leak here**
DemoAppDelegate *appDelegate = (DemoAppDelegate *)[UIApplication sharedApplication].delegate;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleSaveNotification:)
name:NSManagedObjectContextDidSaveNotification
object:appDelegate.managedObjectContext];
[self fetch];
}
- (void)fetch {
NSErreur * erreur = nil; BOOL success = [self.fetchedResultsController performFetch: erreur &]; if (! Success) { debugLog (@ "Erreur non gérée lors de l'exécution de fetch:% @", [erreur localiséeDescription]); NSAssert1 (0, @ "Erreur non gérée lors de l'exécution de l'extraction:% @", [erreur localiséeDescription]); } [tableView reloadData];
}
- (NSFetchedResultsController *)fetchedResultsController {
si (fetchedResultsController == nil) { NSFetchRequest * fetchRequest = [[[NSFetchRequest alloc] init] autorelease]; DemoAppDelegate * appDelegate = (DemoAppDelegate *) [UIApplication sharedApplication] .delegate; [fetchRequest setEntity: [NSEntityDescription entityForName: @ "Nouvelles" inManagedObjectContext: appDelegate.managedObjectContext]];
fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest: fetchRequest managedObjectContext: appDelegate.managedObjectContext sectionNameKeyPath: néant cacheName: @ "NewsCache"];
}
return fetchedResultsController; }
- (void)handleSaveNotification:(NSNotification *)aNotification {
DemoAppDelegate * appDelegate = (DemoAppDelegate *) [UIApplication sharedApplication] .delegate; [appDelegate.managedObjectContext mergeChangesFromContextDidSaveNotification: aNotification]; [auto-fetch]; }
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
News *news = [fetchedResultsController objectAtIndexPath:indexPath];
// fill cell.label.text according to the news field value
}
@end
Qu'est-ce qui vous fait penser que cela fuit? Nous avons besoin de plus de code et d'infos sur les objets qui ont fui. – Eiko