【发布时间】:2017-06-13 09:43:55
【问题描述】:
问题: 使用 xcode 工具分析 iOS 应用程序,它似乎是一个很小但至关重要的(sn-p 在整个项目中间接执行)内存泄漏。
描述:我们不使用任何实体引用并遵循典型的苹果建议的核心数据对象上下文堆栈
这里是仪器的屏幕截图,显示由于NSAsynchronousFetchRequest 保持对NSFetchResult 的相互间接引用而导致明显泄漏
根据Instruments
,这里是触发泄漏的代码sn-p(去掉所有不必要的代码,即使[弱自己]仍然没有改变它)let anEntityFetch = NSFetchRequest<NSFetchRequestResult>(entityName: AnEntity.entityName)
let asyncFetchRequest = NSAsynchronousFetchRequest(fetchRequest: rangeQuantityFetch) { (asynchronousFetchResult) -> Void in
//
}
do {
// commenting out the execute there is no leak anymore
_ = try managedObjectContext.execute(asyncFetchRequest)
} catch {
}
启用编译优化标志也会发生同样的事情。
问题:是否有可能只是 Instruments 或 xcode 错误?或者这是一个已知的核心数据问题?或者任何有用的提示来解决我的问题源将不胜感激。
【问题讨论】:
标签: swift core-data memory-leaks swift3 instruments