The awaitMap() extension function for SupportMapFragment uses the non cancellable suspendCoroutine function from the kotlin.coroutines package, so if the map is never shown, it'll never resume, even if cancelled.
The solution is to use suspendCancellationCoroutine from the kotlinx.coroutines package, even if there's no way to unregister the underlying callback in the current Google Maps API for Android.
It's better than what we have now because in the first case, the leaked objects can reach well beyond the SupportMapFragment, while in the second case, we only have a temporary leak (until the callback finally gets called, for example after the map is shown, or once the SupportMapFragment gets garbage collected).
The
awaitMap()extension function forSupportMapFragmentuses the non cancellablesuspendCoroutinefunction from thekotlin.coroutinespackage, so if the map is never shown, it'll never resume, even if cancelled.The solution is to use
suspendCancellationCoroutinefrom thekotlinx.coroutinespackage, even if there's no way to unregister the underlying callback in the current Google Maps API for Android.It's better than what we have now because in the first case, the leaked objects can reach well beyond the
SupportMapFragment, while in the second case, we only have a temporary leak (until the callback finally gets called, for example after the map is shown, or once theSupportMapFragmentgets garbage collected).