When I run this sample app as a command line tool in macOS, after a few seconds it is consuming 1GB of memory and it keeps ramping up from there, until it crashes. I'm not sure what I'm doing wrong. I am waiting for the result of each call to test so it should not be queueing up anything, as far as I can tell, no memory should be retained after each call to `test.
@main
struct TaskGroupTest {
static func test() async {
await withTaskGroup(of: Void.self) { group in
(0..<10).forEach { _ in
group.addTask {}
}
for await _ in group {}
}
}
static func main() async {
for _ in (0..<1000000) {
await Self.test()
}
}
}
Hmmm, looks like I already have 5.6, maybe something else?. Interesting thing - if I put this code in iOS app, no problem. It runs forever without increasing memory.... The problem only happens to me on macOS.
xcrun --find swift
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
xcrun swift -version
swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)