To cut a long story short, here is a code snippet that would easily eat as much memory as it can until it's stopped. But why? When I wrap the scope inside while
in autoreleasepool
, not a single byte is leaked. However it affects only current scope; if there are leaky function calls, leakage will continue. So the answer is to just wrap leak-prone operations in autoreleasepool? It looks kinda ridiculous and non-swifty.
import Foundation
while true {
let _ = "Foo Bar".data(using: .ascii)
usleep(100)
}