Skip to content

fix(perf): Make FirstDrawDoneListener cleanup OnGlobalLayoutListener after use#8322

Open
romtsn wants to merge 2 commits into
firebase:mainfrom
romtsn:rz/fix/first-draw-done-listener-leak
Open

fix(perf): Make FirstDrawDoneListener cleanup OnGlobalLayoutListener after use#8322
romtsn wants to merge 2 commits into
firebase:mainfrom
romtsn:rz/fix/first-draw-done-listener-leak

Conversation

@romtsn

@romtsn romtsn commented Jun 18, 2026

Copy link
Copy Markdown

Description

The OnGlobalLayoutListener registered in onDraw() to defer removal of the OnDrawListener is never itself removed from the ViewTreeObserver. In single-Activity apps, this causes a per-registration leak — one listener per registerForNextDraw call — each pinning the view and callback on the VTO indefinitely.

The fix makes the OnGlobalLayoutListener remove 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 mOnGlobalLayoutListeners is empty after the cleanup fires.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

@google-cla

google-cla Bot commented Jun 18, 2026

Copy link
Copy Markdown

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.

romtsn added 2 commits June 18, 2026 14:25
…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.
@romtsn romtsn force-pushed the rz/fix/first-draw-done-listener-leak branch from 353f50b to fa044bf Compare June 18, 2026 12:26
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.

1 participant