I am working on a ViewController where I called my viewModel to do a DispatchQueue.async call. After the async task starts and before the end my task ViewController is deinited by pressing the back button. In that case, what will be happened to my async task? Is it gonna hold a thread or a memory block or cause a memory leak? If that happens, is there any way to cancel my async task?
For understanding, I am adding demo classes:
Class A: ViewController {
let viewModel = B()
func callViewModelAsyncFunction() {
viewModel.viewModelAsyncFunction()
}
}
Class B {
private let sessionQueue = DispatchQueue(label: "Session.Queue")
private let sessionGroup = DispatchGroup()
func viewModelAsyncFunction() {
sessionQueue.async {
self.sessionGroup.wait()
self.sessionGroup.enter()
//do my other task signal producer call {
//}
}
}
}
Since no one goona respond to my naive question, I do some experiments, and here is my experiment code on Playgrounds
And experiment result is
From my experiment, I understand that