Title: `FirstDrawDoneListener` still leaks one react-native-screens fragment per navigation after #5567 · Issue #6357 · getsentry/sentry-java · GitHub
Open Graph Title: `FirstDrawDoneListener` still leaks one react-native-screens fragment per navigation after #5567 · Issue #6357 · getsentry/sentry-java
X Title: `FirstDrawDoneListener` still leaks one react-native-screens fragment per navigation after #5567 · Issue #6357 · getsentry/sentry-java
Description: Integration sentry-android (through @sentry/react-native) Version sentry-android 8.61.0 (@sentry/react-native 8.31.0) Steps to Reproduce React Native app (RN 0.81.5, new architecture) with a native stack (react-native-screens 4.17.1) and...
Open Graph Description: Integration sentry-android (through @sentry/react-native) Version sentry-android 8.61.0 (@sentry/react-native 8.31.0) Steps to Reproduce React Native app (RN 0.81.5, new architecture) with a native...
X Description: Integration sentry-android (through @sentry/react-native) Version sentry-android 8.61.0 (@sentry/react-native 8.31.0) Steps to Reproduce React Native app (RN 0.81.5, new architecture) with a native...
Opengraph URL: https://github.com/getsentry/sentry-java/issues/6357
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`FirstDrawDoneListener` still leaks one react-native-screens fragment per navigation after #5567","articleBody":"### Integration\n\nsentry-android (through `@sentry/react-native`)\n\n### Version\n\nsentry-android 8.61.0 (`@sentry/react-native` 8.31.0)\n\n### Steps to Reproduce\n\n1. React Native app (RN 0.81.5, new architecture) with a native stack (`react-native-screens` 4.17.1) and `reactNavigationIntegration({ enableTimeToInitialDisplay: true })`.\n2. Push a screen onto the stack, wait for it to render, then go back. Repeat 11 times.\n3. Force a GC and take a heap dump (`am dumpheap -g`).\n\n### Expected Result\n\nThe popped `ScreenStackFragment`s are collected.\n\n### Actual Result\n\nEach push leaves one `ScreenStackFragment` and its whole native view tree in memory. On a 256 MB heap device the app ends in `OutOfMemoryError` after long sessions.\n\nCounts after a forced GC, 11 push/pop cycles:\n\n| Class | Before | After |\n|---|---|---|\n| `com.swmansion.rnscreens.ScreenStackFragment` | 3 | 14 |\n| `io.sentry.android.core.internal.util.FirstDrawDoneListener` | 1 | 12 |\n| `com.facebook.react.views.view.ReactViewGroup` | 143 | 638 |\n\nRetention path:\n\n```\nViewRootImpl\n .mAttachInfo -> View$AttachInfo\n .mTreeObserver -> ViewTreeObserver\n .mOnGlobalLayoutListeners -> ViewTreeObserver$CopyOnWriteArray\n .[n] -> FirstDrawDoneListener$2\n .val$view -> com.swmansion.rnscreens.stack.views.ScreensCoordinatorLayout\n .fragment -> com.swmansion.rnscreens.ScreenStackFragment\n```\n\n### Cause\n\n#5567 (fix for #5495) makes the `OnGlobalLayoutListener` call `view.getViewTreeObserver().removeOnGlobalLayoutListener(this)`. That does not work for the views `RNSentryReactFragmentLifecycleTracer` registers:\n\n1. `onDraw()` adds the layout listener to the window's `ViewTreeObserver`.\n2. A static screen has no layout pass after its first draw, so the listener does not run yet.\n3. The next layout pass comes when the screen is popped. The fragment view is already detached, so `view.getViewTreeObserver()` returns the view's own floating observer, not the window's.\n4. The remove call does nothing. The listener stays on the window's observer and keeps the detached view alive.\n\n### Fix\n\n#6152 fixes it: it posts the `OnDrawListener` removal to the main thread right after the draw and drops the layout listener. We applied the same change with patch-package (a copy of the listener in `@sentry/react-native` used by `RNSentryReactFragmentLifecycleTracer`) and ran the same test:\n\n| Class | Before | After 11 cycles |\n|---|---|---|\n| `ScreenStackFragment` | 3 | 4 |\n| `FirstDrawDoneListener` | 1 | 1 |\n| `ReactViewGroup` | 143 | 190 |\n\nThis matches `enableTimeToInitialDisplay: false`, so the leak is gone with TTID still on. The #6152 description says the old behaviour \"isn't a memory leak\" because everything dies with the activity. In a single-Activity React Native app the activity lives for the whole session, so it is an unbounded leak. We would be glad to see #6152 merged.\n","author":{"url":"https://github.com/correalm","@type":"Person","name":"correalm"},"datePublished":"2026-10-22T14:17:02Z","url":"https://github.com/getsentry/sentry-java/issues/6357"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ead9b095-8cbe-160f-b99b-04da85de8118 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BA08:133E28:133EEA:1B00A0:6B046587 |
| html-safe-nonce | d66052f25f2d5b16fe2c0ce5d01afbcd5d188233254f04995fdf9c7da5518af6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQTA4OjEzM0UyODoxMzNFRUE6MUIwMEEwOjZCMDQ2NTg3IiwidmlzaXRvcl9pZCI6Ijc0NDEzNDM2OTE4MjgyNTgxODMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2a436e1587276143b8e090194a673af3925b0200c168b1c4f1784a142f90c0db |
| hovercard-subject-tag | issue:5981122447 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-java/6357/issue_layout |
| twitter:image | https://opengraph.githubassets.com/647dd4e196d5740f4b19a555110cf7ccabe7bdc5b0bb9a87f58bf5a6543e2cb8/getsentry/sentry-java/issues/6357 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/647dd4e196d5740f4b19a555110cf7ccabe7bdc5b0bb9a87f58bf5a6543e2cb8/getsentry/sentry-java/issues/6357 |
| og:image:alt | Integration sentry-android (through @sentry/react-native) Version sentry-android 8.61.0 (@sentry/react-native 8.31.0) Steps to Reproduce React Native app (RN 0.81.5, new architecture) with a native... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | correalm |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-java git https://github.com/getsentry/sentry-java.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3368190 |
| octolytics-dimension-repository_nwo | getsentry/sentry-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3368190 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width