Iphone self.tableView.delegate=self和self.table.dataSource=self内存泄漏
我有以下代码,这些代码在设备上有内存泄漏,您能帮我检查一下吗?谢谢Iphone self.tableView.delegate=self和self.table.dataSource=self内存泄漏,iphone,delegates,datasource,memory-leaks,tableview,Iphone,Delegates,Datasource,Memory Leaks,Tableview,我有以下代码,这些代码在设备上有内存泄漏,您能帮我检查一下吗?谢谢 @interface NewsListViewController : UIViewController<UITableViewDataSource, UITableViewDelegate> { @private UITableView *tableView; NSFetchedResultsController *fetchedResultsController; ...... } @propert
@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];
n错误*错误=nil;
BOOL success=[self.fetchedResultsController性能检测:&错误];
如果(!成功){
调试日志(@“执行获取时未处理的错误:%@,[error localizedDescription]);
NSAssert1(0,@“执行获取时出现未处理的错误:%@,[error localizedDescription]);
}
[tableView重新加载数据]
}
- (NSFetchedResultsController *)fetchedResultsController {
if(fetchedResultsController==nil){
NSFetchRequest*fetchRequest=[[[NSFetchRequest alloc]init]autorelease]
DemoAppDelegate*appDelegate=(DemoAppDelegate*)[UIApplication sharedApplication]。委派;
[fetchRequest setEntity:[NSEntityDescription entityForName:@“新闻”
inManagedObjectContext:appDelegate.managedObjectContext]]
fetchedResultsController=[[NSFetchedResultsController alloc]initWithFetchRequest:fetchRequest
managedObjectContext:appDelegate.managedObjectContext
sectionNameKeyPath:无
cacheName:@“新闻缓存”]
返回获取的ResultsController;
}
DemoAppDelegate*appDelegate=(DemoAppDelegate*)[UIApplication sharedApplication]。委派;
[appDelegate.managedObjectContext合并更改fromContextDidSaveNotification:aNotification];
[自取];
}
设置UITableView实例的委托或数据源属性不太可能导致明显的内存泄漏
您应该更彻底地检查周围的代码。是什么让您认为这会泄漏?我们需要更多关于泄漏对象的代码和信息。@Eiko,Ryan,谢谢你的回复,我添加了更多的详细代码,我使用核心数据在tableView中为单元格提供数据,我不知道泄漏发生的原因。你能帮我查一下吗?提前谢谢!更多的代码是好的,但仍然不够。你正在适当地释放和保留一切。正如Eiko之前所问的:是什么让你认为这会泄露?你用仪器检查过吗?是的,仪器显示有泄漏。但是负责的lib是UIKit而不是我的应用程序,我可以忽略它吗?谢谢
}
- (NSFetchedResultsController *)fetchedResultsController {
}
- (void)handleSaveNotification:(NSNotification *)aNotification {
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
News *news = [fetchedResultsController objectAtIndexPath:indexPath];
// fill cell.label.text according to the news field value
}
@end