Can someone clarify one thing about Swift memory management?
I have the following application delegate:
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
private let _queue = NSOperationQueue()
func applicationDidFinishLaunching(aNotification: NSNotification) {
_queue.maxConcurrentOperationCount = 1
_queue.addOperation(Operation())
_queue.addOperation(Operation())
_queue.addOperation(Operation())
}
}
private class Operation: NSOperation {
override func main() {
autoreleasepool {
var d = [String: AnyObject]()
for i in 1...1000 {
d[i.description] = Repeat(count: 10000, repeatedValue: "ABCDEF").joinWithSeparator("")
}
d.removeAll()
}
}
}
After starting the application, I start three synchronous operations. Each operation simply creates a very large dictionary (struct) with very large strings (also structs).
Since all the data created is a value type and nothing was captured, I believe that memory should be released when the main function ends. In fact, I added d.RemoveAll()just in case to free up memory.
After completing all operations, Activity Monitor displays the following information:

- 26.7mb, _queue.addOperation(Operation()), 7mb. 19 , ?
@Lou Franco
func applicationDidFinishLaunching(aNotification: NSNotification) {
for _ in 1...100 {
_queue.addOperation(Operation())
}
}
8 . 40 . 100 000 . 40 . 600... 1000 , .