gpt4 book ai didi

iphone - NSFetchedResultsController objectAtIndex 的内存泄漏

转载 作者:行者123 更新时间:2023-12-03 16:39:26 27 4
gpt4 key购买 nike

我在使用 NSFetchedResultsController objectAtIndex 时出现内存泄漏:栈帧如下:

   0 CoreFoundation __CFDataAllocate
1 CoreFoundation __CFDataInit
2 CoreData -[NSSQLCore _prepareResultsFromResultSet:usingFetchPlan:withMatchingRows:]
3 CoreData -[NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument:]
4 CoreData -[NSSQLCore newRowsForFetchPlan:]
5 CoreData -[NSSQLCore objectsForFetchRequest:inContext:]
6 CoreData -[NSSQLCore executeRequest:withContext:error:]
7 CoreData -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
8 CoreData -[NSManagedObjectContext executeFetchRequest:error:]
9 CoreData _faultBatchAtIndex
10 CoreData -[_PFBatchFaultingArray objectAtIndex:]
---> 11 MyApp -[DocumentViewController tableView:heightForRowAtIndexPath:]
12 UIKit -[UISectionRowData refreshWithSection:tableView:tableViewRowData:]
13 UIKit -[UITableViewRowData rectForFooterInSection:]
14 UIKit -[UITableViewRowData heightForTable]
15 UIKit -[UITableView(_UITableViewPrivate) _updateContentSize]
16 UIKit -[UITableView noteNumberOfRowsChanged]
17 UIKit -[UITableView reloadData]
18 UIKit -[UITableView layoutSubviews]
19 QuartzCore -[CALayer layoutSublayers]
20 QuartzCore CALayerLayoutIfNeeded
21 QuartzCore CA::Context::commit_transaction(CA::Transaction*)
22 QuartzCore CA::Transaction::commit()
23 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
24 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
25 CoreFoundation __CFRunLoopDoObservers
26 CoreFoundation __CFRunLoopRun
27 CoreFoundation CFRunLoopRunSpecific
28 CoreFoundation CFRunLoopRunInMode
29 GraphicsServices GSEventRunModal
30 GraphicsServices GSEventRun
31 UIKit UIApplicationMain

从这个堆栈帧来看,使用 objectAtIndex 访问的对象似乎被泄漏了。

但是,当我离开 Controller 时,它的 dealloc 方法会被调用。在这个方法中,由于我使用了[NSManagedObjectContextfreshObject:mergeChange],所以由fetchedresultscontroller获取的所有对象都会变成错误。

为了使我的描述更加完整,下面是创建泄漏对象的代码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
Page* page = [[self fetchedResultsController] objectAtIndexPath:indexPath];
UIImage* thumbnail = [page getThumbnail];
[[self managedObjectContext] refreshObject:page.image mergeChanges:NO];
CGFloat height = [PageCell cellImageSize:thumbnail].height + 20;
return height;
}

任何提示将不胜感激,谢谢!

最佳答案

检查获取 UIImage 的代码。泄漏很可能就在那里。它的确切位置取决于您如何创建图像对象。

关于iphone - NSFetchedResultsController objectAtIndex 的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3216184/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com