我正在试验 NSProgress,在后台线程上找到一个简单的循环会导致内存快速增长:
class Worker {
var progress:NSProgress?
func doWork() {
let numIterations:Int64 = 100000
let delay:UInt32 = 100
let progressObj = NSProgress(totalUnitCount: numIterations)
// progressObj.cancellable = true
progress = progressObj
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0)) {
progressObj.becomeCurrentWithPendingUnitCount(numIterations)
for i in 0...numIterations {
progressObj.completedUnitCount = i
usleep(delay)
}
progressObj.resignCurrent()
}
}
}
使用 Allocations 工具对此进行分析显示内存在 30 秒内增长到约 20mb(如果我增加循环的大小,则更多)。分配都归于_NSProgressFraction
.
有什么明显的我忽略了,或者这是 NSProgress 的一个错误?