Closed OmarELRayes closed 2 years ago
That's what I'm currently using to avoid the memory leak.
override fun onDestroyView() {
//because of ViewPager2's adapter memory leak, can't be accessed via binding at this state
view?.findViewById<ViewPager2>(R.id.imagesViewPager)?.adapter = null
super.onDestroyView()
}
Yeah, I've faced same issue as well. I have two fragments (list of items and details page), let's call them A and B.
When I navigate A -> B onViewDestroyed
of A fragment is called as intended. But when I do popBackStack
inside B fragment and navigate to A fragment again onViewDestroyed
of A fragment is called right after onViewCreated
have the issue been solved ?
I hope yes. The fix will be in 1.5.2. The artefacts are processing by Maven Central right now
I have 3 Fragments, Splash->Introduction->Login using Single Activity Architecture. the
IntroductionFragment
got aViewPager2
andLeakCanary
shows a memory leak because of the adapter so I have to set it to benull
inOnDestoyView()
so here is the code I usehowever what happens that the view pager shows the images then 'OnViewDestroyed' gets called from your library clearing the adapter before leaving the fragment
GIF showcasing the behavior : https://gyazo.com/fdf0e31fdb9a9ae4bd64714c42d1ce17