fix(perf): Make FirstDrawDoneListener cleanup OnGlobalLayoutListener after use#8322
fix(perf): Make FirstDrawDoneListener cleanup OnGlobalLayoutListener after use#8322romtsn wants to merge 2 commits into
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…after use The OnGlobalLayoutListener registered in onDraw() to defer removal of the OnDrawListener was never itself removed. In single-Activity apps this causes an unbounded per-navigation leak on the ViewTreeObserver, accumulating one listener per registerForNextDraw call. Make the OnGlobalLayoutListener remove itself after firing.
353f50b to
fa044bf
Compare
Description
The
OnGlobalLayoutListenerregistered inonDraw()to defer removal of theOnDrawListeneris never itself removed from theViewTreeObserver. In single-Activity apps, this causes a per-registration leak — one listener perregisterForNextDrawcall — each pinning the view and callback on the VTO indefinitely.The fix makes the
OnGlobalLayoutListenerremove itself after firing.This was discovered in Sentry's Android SDK, which adapted this code. See: getsentry/sentry-java#5495
Testing
Added a regression test that verifies
mOnGlobalLayoutListenersis empty after the cleanup fires.