Deinit and MainActor

Late to the party here, but I'm curious how folks would go about canceling a stored task if not allowed to do so on deinit. We have View Models that are ObservableObjects and keep handles on the tasks to cancel them if the ViewModel is deinitialized. Is the only solution making a call from the View .onDisappear instead? What if it weren't tied directly to a view?