我有以下代码,其中有内存泄漏的设备,您可以帮助检查它吗?谢谢。
@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];自获取;
}
- (void)fetch {NSError *error = nil;BOOL success = self.fetchedResultsController性能获取:& error;if (!success) {debugLog(@“执行抓取时出现未处理错误:%@",error localizedDescription);NSAssert1(0,@”执行抓取时出现未处理错误:%@",error localizedDescription);} tableView reloadData;
}
- (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"];
}返回fetchedResultsController;}
- (void)handleSaveNotification:(NSNotification *)aNotification {DemoAppDelegate * mergeChangesFromContextDidSaveNotification:aNotification;= (DemoAppDelegate *)UIApplication sharedApplication.delegate;appDelegate.managedObjectContext appDelegate自取;}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
News *news = [fetchedResultsController objectAtIndexPath:indexPath];
// fill cell.label.text according to the news field value
}
@end发布于 2010-09-11 03:25:12
设置UITableView实例的委托或dataSource属性不太可能导致明显的内存泄漏。
您应该更彻底地检查周围的代码。
https://stackoverflow.com/questions/3687589
复制相似问题