首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >self.tableView.delegate = self和self.table.dataSource = self内存泄漏

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

Stack Overflow用户
提问于 2010-09-11 03:13:13
回答 1查看 1.7K关注 0票数 0

我有以下代码,其中有内存泄漏的设备,您可以帮助检查它吗?谢谢。

代码语言:javascript
复制
@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];

自获取;

代码语言:javascript
复制
}

- (void)fetch {

NSError *error = nil;BOOL success = self.fetchedResultsController性能获取:& error;if (!success) {debugLog(@“执行抓取时出现未处理错误:%@",error localizedDescription);NSAssert1(0,@”执行抓取时出现未处理错误:%@",error localizedDescription);} tableView reloadData;

代码语言:javascript
复制
}

 - (NSFetchedResultsController *)fetchedResultsController {

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

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

fetchedResultsController = [NSFetchedResultsController alloc :fetchRequest:nil cacheName:@"NewsCache"];

代码语言:javascript
复制
}

返回fetchedResultsController;}

代码语言:javascript
复制
 - (void)handleSaveNotification:(NSNotification *)aNotification {

DemoAppDelegate * mergeChangesFromContextDidSaveNotification:aNotification;= (DemoAppDelegate *)UIApplication sharedApplication.delegate;appDelegate.managedObjectContext appDelegate自取;}

代码语言:javascript
复制
 - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    News *news = [fetchedResultsController objectAtIndexPath:indexPath];

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

 }   

 @end
EN

回答 1

Stack Overflow用户

发布于 2010-09-11 03:25:12

设置UITableView实例的委托或dataSource属性不太可能导致明显的内存泄漏。

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3687589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档