Skip to content

fix : leaks at Media Detail Fragment #6705

Open
rovertrack wants to merge 2 commits intocommons-app:mainfrom
rovertrack:leakcanary
Open

fix : leaks at Media Detail Fragment #6705
rovertrack wants to merge 2 commits intocommons-app:mainfrom
rovertrack:leakcanary

Conversation

@rovertrack
Copy link
Contributor

@rovertrack rovertrack commented Mar 4, 2026

Fixes #6692

What changes did you make and why?

MediaDetailAdapter.kt

  • guard to make sure mediaDetailPagerFragment is not access after removal

MediaDetailFragment.kt

  • Replaced OnGlobalLayoutListener with doOnNextLayout for autocleanup
  • Introduced a fragmentHandler to clear callbacks on onDestroyView()
  • Nullifies _binding and media image view controller to avoid leaks

MediaDetailPagerFragment.kt

  • binding = null and adapter = null in onDestroyView().
  • Uses CompositeDisposable to prevent RxJava leaks.
  • Uses binding.itemProgressBar instead of findViewById as it is access only once to avoid cleanup

MediaDetailFragmentUnitTests.kt

  • Removed layoutListener mock testing since the obsolete OnGlobalLayoutListener was removed

Screenshots (for UI changes only)

VID_20260305004734.mp4

@rovertrack rovertrack force-pushed the leakcanary branch 3 times, most recently from 3c46c15 to cdf1b11 Compare March 4, 2026 19:10
@rovertrack rovertrack marked this pull request as ready for review March 4, 2026 19:13
@rovertrack
Copy link
Contributor Author

@neeldoshii i have fixed leaks around Media Detail Fragment & Contribution Fragment
and many more which i encountered while fixing and testing the app
i think it solves most of the leaks persisting
please test it and let me know if it solves the issue )

@rovertrack rovertrack changed the title fix : leaks at at Media Detail Fragment & Contribution Fragment and more .. fix : leaks at Media Detail Fragment & Contribution Fragment and more .. Mar 4, 2026
@neeldoshii neeldoshii marked this pull request as draft March 8, 2026 17:16
@neeldoshii neeldoshii self-requested a review March 8, 2026 17:16
Copy link
Collaborator

@neeldoshii neeldoshii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rovertrack, thanks for working on the memory leaks! Would it be possible to keep each PR focused on a specific leak or file? It’s a bit hard to review when it mentions “many more which I encountered.”

Instead, could you provide specific details about each leak you're solving? That would make it much easier to review and understand the RCA. Also, it would help if each PR focuses on solving one issue at a time.

Feel free to split them into multiple PRs (one per memory leak) if that works better. It will make them easier to review and maintain. :-)

@rovertrack rovertrack marked this pull request as ready for review March 9, 2026 15:52
@rovertrack rovertrack requested a review from neeldoshii March 9, 2026 15:53
@rovertrack
Copy link
Contributor Author

@neeldoshii i have separated the PRs for separate leaks as follow up for this PR

position
} else {
binding!!.mediaDetailsPager.currentItem
pager.currentItem
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I haven't read the entire code, but just to confirm once, this line addresses the issue I mentioned in this PR: #6624, is it? 🙂

We'll test it a bit intensively as we've seen regressions in at least two PRs. Thanks for your patience.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly yes , because many cases it tries to access that pager after destroyed which results in ANR ,null pointer

sure , anything as long as it solves the issue )

@rovertrack rovertrack changed the title fix : leaks at Media Detail Fragment & Contribution Fragment and more .. fix : leaks at Media Detail Fragment Mar 9, 2026
@rovertrack
Copy link
Contributor Author

@RitikaPahwa4444 is this pr good ? As far as I have tested it solved the leaks !

@github-actions
Copy link

✅ Generated APK variants!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ANR at Media Detail Fragment & Contribution Fragment

3 participants