I am experimenting with NSProgress, and finding a simple loop on a background thread causes memory to grow rapidly:
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()
}
}
}
Profiling this with the Allocations instrument shows memory grow to about 20mb over 30 seconds (more if I increase the size of the loop). The allocations are all attributed to _NSProgressFraction
.
Is there something obvious I'm overlooking, or is this a bug with NSProgress?