https://kotlinlang.org logo
#coroutines
Title
# coroutines
a

Almas Shagdarov

05/26/2021, 4:21 AM
Hi everyone. Who can help me my coroutine job leaks i dont get  it why?
Copy code
private var searchJob: Job? = null
private fun search(query: String = "") {
        searchJob?.cancel()
        searchJob = viewLifecycleOwner.lifecycleScope.launchWhenStarted {
            viewModel.searchTaskList(query).collectLatest {
                adapter?.submitData(it)
            }
        }
    }
LeaksCanary: Fragment received onDestroy callback and FragmentManager is null
z

zkeme

05/26/2021, 11:24 AM
Just by looking at this, I can't tell. The scope where you're launching should be canceled when view goes away 😕
u

ursus

05/26/2021, 12:31 PM
if you clear searchJob manually does it shut up?
a

Almas Shagdarov

05/26/2021, 2:29 PM
@zkeme No it is not
@ursus I tried clearing onDestroyView , onDestroy
@ursus worked on onStop but interesting that launchWhenStated dont work it is active in onViewCreated
d

dshevliakov

05/26/2021, 7:52 PM
I'm not very familiar with leaks canary. Can you explain how you know that job is leaking by this message
LeaksCanary: Fragment received onDestroy callback and FragmentManager is null
?
5 Views