Possible memory leak in withTaskGroup(of:) concurrency method (FB9719809)

I created a simplified project and filed a feedback to illustrate the potential memory leak using withTaskGroup(of:). I say potential leak as perhaps I'm doing something proscribed, but I believe I've followed the recipe supplied in the Apple docs.

class TaskGroup {
    
   static func perform() async {

        let _ = await withTaskGroup(of: Void.self) { group in
            for _ in 0..<18 {
                group.addTask(priority: .userInitiated) {
                    await AsyncJob.job()
                }
            }
            return
        }
    }
}

actor AsyncJob {

	static func job() async {
		syncJob()
	}
}

func syncJob() {
	var value: Double = 0
	for count in 0..<100_000 {
		value += Double(count)
	}
}


The resulting stack trace when the above code is run inside the simplified app. I've confirmed this trace on a physical device (iPhone 8).

We fixed those leaks (see those PRs), those two specifically:

both of which made it to apple:release/5.5-08092021

Are you sure you are using the toolchain / Xcode?

2 Likes

Thanks for the prompt reply (and on weekend)! Will these fixes ship with Xcode 13.2 this week? While the toolchain version may have fixed the leaks, I'd like to deploy to the App Store.

i tested those issues about a month ago, and found they only occur on linux, not mac OS. are we sure this is the same issue?

1 Like

Seems like there might still be a residual leak in the toolchain version.

When I fixed those issues I did confirm there was no leaks occurring on linux.

Thanks for the note Tony, perhaps something else happened since.

I am also seeing this behaviour with my application leaking gigabytes of memory on macOS with Xcode 13.2 Beta (13C5066c) since adopting withTaskGrou(of:). My experience seems very similar to the Linux issue here:

Disregard - I hadn't realised that that machine was still on a Beta version of Monterey. After upgrading to the stable release the issue is resolved.

1 Like

I'm happy to hear that, was worried we missed something else still (and quite confused, since I checked many times and seemed fine, on all OSes, there were multiple issues after all).

Thanks for confirming, @mikecsh !

Terms of Service

Privacy Policy

Cookie Policy