self.tableView.delegate = self和self.table.dataSource =自我内存泄漏

我有以下代码,它们在设备上有内存泄漏,请你帮忙检查一下吗? 谢谢。

@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 {

NSError * error = nil; BOOL成功= [self.fetchedResultsController performFetch:&error]; 如果(!成功){debugLog(@“未处理的错误执行提取:%@”,[错误localizedDescription]); NSAssert1(0,@“执行抓取的未处理错误:%@”,[error localizedDescription]); } [tableView reloadData];

}

 - (NSFetchedResultsController *)fetchedResultsController {

if(fetchedResultsController == nil){NSFetchRequest * fetchRequest = [[[[NSFetchRequest alloc] init] autorelease];

DemoAppDelegate * appDelegate =(DemoAppDelegate *)[UIApplication sharedApplication] .delegate; [fetchRequest setEntity:[NSEntityDescription entityForName:@“News”inManagedObjectContext:appDelegate.managedObjectContext]];

fetchedResultsController = [[NSFetchedResultsController的alloc] initWithFetchRequest:fetchRequest managedObjectContext:appDelegate.managedObjectContext sectionNameKeyPath:无cacheName:@ “NewsCache”];

}

返回fetchedResultsController; }

 - (void)handleSaveNotification:(NSNotification *)aNotification {

DemoAppDelegate * appDelegate =(DemoAppDelegate *)[UIApplication sharedApplication] .delegate; [appDelegate.managedObjectContext mergeChangesFromContextDidSaveNotification:aNotification]; [self fetch]; }

 - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    News *news = [fetchedResultsController objectAtIndexPath:indexPath];

    // fill cell.label.text according to the news field value

 }   

 @end

设置UITableView实例的委托或数据源属性可能会导致明显的内存泄漏,这在天文上不太可能。

你应该更彻底地检查你周围的代码。

链接地址: http://www.djcxy.com/p/36103.html

上一篇: self.tableView.delegate = self and self.table.dataSource = self memory leak

下一篇: How can I change section ordering with NSFetchedResultsController?