Repository navigation
Description
Description
On react-native 0.83.6 (new architecture / bridgeless, Hermes), every mount of a host component wraps its shadow node in a facebook::react::ShadowNodeWrapper — a jsi::NativeState holding std::shared_ptr<const ShadowNode>, created per host component by valueFromShadowNode (ReactCommon/react/renderer/uimanager/primitives.h:29–43; std::make_shared<ShadowNodeWrapper> at :33, jsi::Object::setNativeState at :41). When the screen unmounts — DeleteView instructions are emitted and executed, the mounting registry returns to baseline — the wrapper set is never released. While one wrapper stays alive it pins, all strong: the node's children_ subtree (ShadowNode.h:138–139 — the UIManager::createNode bytes), props_ (RawProps::toDynamic → YogaStylableProps bytes), and family_ (ShadowNodeFamily → mostRecentState_, eventEmitter_, instanceHandle_). One wrapper per unmounted host component ⇒ one whole popped screen's shadow graph retained per navigation cycle: ~1.0–1.5 MB per push/pop in our measurements (11.7/14.3 KB per view-entry per cycle).
The retained set is live-rooted, not garbage awaiting collection: it survives forced Hermes GC, and it survives ReactDelegate.unloadApp()/stopSurface() — even with a forced GC after the unload, recovery is only 19–25% (measured 25.2% by dumpsys meminfo; 81% of sampled retained bytes persist per heapprofd). The root is at ReactInstance scope, above the surface: after unloadApp() the shadow tree is removed from the registry (native probe: registryCount=0) while ~75–81% of the accumulated bytes persist.
What keeps each wrapper's JS object alive after unmount is a per-unmounted-component live JS residue: js_allocatedBytes after 4× forced GC grows +71.5 / +75.4 KB per cycle (mean +73.5 KB/cyc, byte-constant across checkpoints) and itself survives unloadApp() — the same signature class as #57198's byte-constant ~566 B/row post-GC residue, at our screen's scale.
This is the same never-reclaimed shape as #57198; this report adds the named retention medium with source pointers, the surface-restart boundary measured with forced GC, the tree-scoped-holder refutation (native probe), and shows the class reproduces without Reanimated and without react-navigation.
Environment
- react-native 0.83.6 (the class also reproduces on 0.86.0-rc.3 via Memory not reclaimed after unmounting a screen with many components, across repeated navigations (New Architecture / Fabric, 0.86.0-rc.3) #57198's repro and 0.86.3 via the Remove Jackson dependency #10521-class repros), react 19.2.0, new architecture / bridgeless, Hermes
- @react-navigation/stack 7.9.3, react-native-screens 4.23.x, react-native-reanimated 4.2.1 / worklets 0.7.4 (present in the app but not required for the repro)
- Android: Pixel 8 Pro (Android 17) and emulator (API 36); release builds measured for slopes (dev builds reproduce the class), dev-flavor debug build for the probe instrumentation (P1/P2, per-site heapprofd) — the slope replicates across builds and runs (+1,005.1 / +963.6 / +973.0 KB/cyc across three probe runs vs +1,018.2 probe anchor)
The retention path (source-verified, RN 0.83.6)
UIManager::createNode (UIManager.cpp:61–104)
allocates per host component:
ConcreteShadowNode (operator new → malloc) ← heapprofd: createNode / clone rows
ShadowNodeFamily, initial State
Props = cloneProps → YogaStylableProps ← heapprofd: RawProps::toDynamic → jsi::dynamicFromValue
returned to JS wrapped:
valueFromShadowNode (primitives.h:29–43)
→ std::make_shared<ShadowNodeWrapper>(node) // ShadowNode.h tail: jsi::NativeState { shared_ptr<const ShadowNode> }
→ jsi::Object.setNativeState(runtime, wrapper) // JS host object owns shared_ptr<ShadowNode>
unmount (DeleteView emitted + executed; registry flat at baseline):
the wrapper JS object SHOULD become garbage — a per-component live JS residue keeps it alive
while ANY wrapper is alive it pins (all strong):
ShadowNode::children_ → entire subtree (ShadowNode.h:138–139)
ShadowNode::props_ → YogaStylableProps + RawProps dynamic
ShadowNode::family_ → mostRecentState_ / eventEmitter_ / instanceHandle_ (ShadowNodeFamily.h)
⇒ one whole popped screen graph per cycle = exactly the createNode/RawProps allocation classes,
11.7–14.3 KB per view-entry per cycle, GC-immune while the residue is live, above the surface.
What we ruled out (this is the useful part)
SurfaceMountingManager.mTagToViewStatedoes NOT accumulate. Per-cycle registry census across 20 push/pop cycles: Settings arm 90 entries at every rest (177 while mounted = Home 90 + Settings 87), Forest-stage arm 78/149/78.detachedParentNull= 0,windowDetached= 0,mViewsToDeleteAfterTouchFinishes= 0 everywhere.- Delete instructions ARE emitted and executed on unmount (registry back to baseline within the pop's settle window) — the retention is downstream of view deletion, not a missing-DELETE bug (data point for Android removes and deletes every view of an unmounted subtree inside the frame that unmounts it #59448's emit-vs-execute question, on 0.83.6).
- Not surface-scoped, and not a GC-cadence artifact.
ReactDelegate.unloadApp()+ remount recovers only 15.6%/15.8% (no forced GC in that run); with 4× forced GC after the unload recovery is still only 4,896/19,461 KB = 25.2% (heapprofd: 81% of sampled retained bytes persist). Surface shedding + GC does not mitigate — the immunity claim is unconditional. - Not tree-scoped (native probe + source walk).
UIManager::stopSurfaceremoves and destroys theShadowTree(UIManager.cpp:265–294);ShadowTreeholds a singlecurrentRevision_(ShadowTree.h:151— no revision history);MountingCoordinatoris single-slot (baseRevision_/lastRevision_). Native readouts at every rest:registryCount=1, node count flat (155);lockCount=0 captured=0forLazyShadowTreeRevisionConsistencyManager::capturedRootShadowNodesForConsistency_(consistency/LazyShadowTreeRevisionConsistencyManager.h:44— the only persistent strong-node map in all of ReactCommon; bounded to 1 root/surface, cleared every JS task). Post-unloadApp:registryCount=0while 74.8–81% of the bytes persist — decisive against any tree/registry-scoped holder. (mDeallocatedShadowNodeRegistry-class caches do not exist in 0.83.6 — grep 0 hits.) - Not a pure-C++ retainer: a live JS residue roots it. After 4× forced GC at each rest:
js_allocatedBytes8,935,984 → 9,651,400 (c10) → 10,405,144 (c20) = +71.5 / +75.4 KB per cycle (mean +73.5 KB/cyc), and the residue survivesunloadApp()+GC (10,354,120 ≈ c20). (Earlier "JS heap flat" readings were instrument-limited — the residue sits inside that instrument's ±1% band; post-forced-GCjs_allocatedBytes, the Memory not reclaimed after unmounting a screen with many components, across repeated navigations (New Architecture / Fabric, 0.86.0-rc.3) #57198 method, is the sensitive instrument.) - Not Reanimated, not navigation. A static screen with zero
react-native-reanimated/Animatedimports reproduces the full slope (per-entry retention only 14.4 vs 11.7 KB/entry·cycle animated vs static — additive, not universal). - Preallocated views bounded out at byte level. The
createViewUnsafeART row is at most TLAB block-accounting noise (registry + Dalvik rows flat); the real freed share is Java view/graphics output (see Numbers).
Numbers
Per push/pop cycle, native heap (NH.Alloc, swap-independent; 20-cycle runs, reduced-motion, warmup discarded):
| arm | OLS slope | endpoint slope | notes |
|---|---|---|---|
| Settings (static content screen) | +791 KB/cyc | +1,018 KB/cyc | zero Reanimated/Animated imports |
| Forest stage (animated content screen) | +991 KB/cyc | +1,019 KB/cyc | 71 vs 87 entries/cycle |
Corpus anchors (same app): +1,051.9 KB/cyc (emulator, devtools off), +1,540.4 KB/cyc OLS (Pixel 8 Pro release, 20-cycle harness). Rate is constant during cycling and flat at rest; content-shaped (a bare-<View> screen is flat/negative).
Three-share accounting of the slope (per-site heapprofd differential: c00-rest → c20-rest → post-unloadApp, 4,096-B sampling; values are heapprofd-derived; sampled totals cover 88–95% of the NH.Alloc slope):
| share | KB/cyc | share of slope | survival at unload+4×GC | sites |
|---|---|---|---|---|
| 1. ShadowNodeWrapper-pinned shadow graph + RawProps dynamic | 620–700 | ~70% | 85–100% | ShadowNode::clone, ConcreteShadowNode<View/Paragraph>::Props, UIManager::createNode, RawProps::toDynamic→jsi::dynamicFromValue, AttributedString::Fragment, InstanceHandle, event emitters |
2. Performance timeline buffer (separate issue: PerformanceEntryKeyedBuffer) |
~148 | ~15% | 100% | PerformanceEntryKeyedBuffer::add → vector push_back [reported separately (#60211)] |
| 3. Java view/graphics output | 85–100 | ~10% | 0–25% | android_view_RenderNode_create, PaintGlue, Bitmap, minikin |
| misc (microtask checkpoint etc.) | ~29 | ~3% | mixed | RuntimeScheduler_Modern::performMicrotaskCheckpoint |
| sum | ~880–970 | ~75–81% survives | vs NH.Alloc slope +963…+1,018 KB/cyc (3 run replicates + probe anchor) |
The ~75–81% survival class = shares 1+2, i.e. everything pinned above the surface; the recovered 19–25% = share 3. (Within share 1, ~0.8 MB of folly::dynamic map/vector sites show low/negative survival — per-site rows below and in the attached tables; the class range is stated conservatively.)
Selected per-site rows (A = c20−c00 / B = post-unload−c00 / survival):
+2.367 / +2.359 / 100% ShadowNode::clone(ShadowNodeFragment)
+1.958 / +1.765 / 90% jsi::dynamicFromValue <- RawProps::toDynamic
+1.843 / +1.835 / 100% ConcreteShadowNode<View>::Props <- UIManager::createNode
+1.614 / +1.479 / 92% UIManager::createNode (direct path)
+1.577 / +1.577 / 100% ConcreteShadowNode<Paragraph>::Props
+0.627 / +0.627 / 100% vector<AttributedString::Fragment>
+0.106 / +0.106 / 100% InstanceHandle::InstanceHandle
+0.623 / +0.025 / 4% android_view_RenderNode_create <- the freed Java class
Repro
- In-app: 20 push/pop cycles of a static, non-animated content screen (no Reanimated, no Animated) reproduces the full slope with a flat mounting registry. Harness recipe:
dumpsys meminfoat c00/c05/c10/c15/c20 rest points, NH.Alloc slope; controls (bare-View screen) stay flat. Live-JS residue:HermesInternal.getInstrumentedStats().js_allocatedBytesafter 4× forced GC at c0/c10/c20 (+73.5 KB/cyc mean). - Minimal external repro (same shape): Memory not reclaimed after unmounting a screen with many components, across repeated navigations (New Architecture / Fabric, 0.86.0-rc.3) #57198's fardad-dev/react-native-memory-leak — mount/unmount a plain content tree via
useStatetoggling, no Reanimated, no react-navigation. Its byte-constant post-GC JS residue (565,936 B/cycle, ~566 B/row) is the same signature class we measure at our screen's scale.
Expected behavior
Unmount must release the mount path's native output (shadow nodes, parsed props, preallocated views) including the per-component wrapper set and the live JS residue that roots it; per-mount native allocations must not survive unmount, and a surface restart must release everything below it. If synchronous teardown of a popped subtree's native graph is not possible, a per-subtree release API would let apps mitigate.
Workaround
None. unloadApp/stopSurface + forced GC recovers only 19–25%; forced GC alone sheds ≤2.5 MB of a 23.4 MB accumulation; there is no per-subtree release API in 0.83.6 (SurfaceMountingManager.deleteView — "we do not handle deleting descendants"). A fix upstream (or a release API) is required.
Root-cause pointers (where to look)
The named medium is ShadowNodeWrapper/ShadowNodeListWrapper (primitives.h:19–43); the open question is what keeps each wrapper's JS object alive after unmount — the live JS residue above. Two mechanism candidates, both per-host-component and ReactInstance-scoped:
- A reconciler-side live residue — the residual of the alternate-fiber shadow-memory class (React-Core Semantic Issue - Unknown type name 'RCT_EXTERN' in RCTBundleURLProvider #33161 /
enableEagerAlternateStateNodeCleanup, commit0411c43b3a, in 0.81+ and evidently insufficient); Memory not reclaimed after unmounting a screen with many components, across repeated navigations (New Architecture / Fabric, 0.86.0-rc.3) #57198's residue measurement is the pointer-level view of this. - An
EventTarget/EventEmitterbookkeeping imbalance closing a per-component C++↔JS cycle:EventTarget::strongInstanceHandle_is a strong JS root held from C++ whileretainCount_ > 0(EventTarget.h/.cpp), andEventEmitter::setEnabledis additive ("a number ofenablecalls should be equal to a number ofdisablecalls to release the event target",EventEmitter.h:53–55), driven byShadowNode::setMounted(ShadowNode.cpp:316–324). An off-by-one per component leaks exactly one whole-subtree graph per host component, forever, GC-immune.
Note PR #59702 (merged 2026-11-05) only bounds the lazy-GC variant (shadow-node native size reported to the JS GC); our retained set survives forced GC — accounting alone will not release this class.
Cross-references
- Memory not reclaimed after unmounting a screen with many components, across repeated navigations (New Architecture / Fabric, 0.86.0-rc.3) #57198 — same shape, and now the same signature class (byte-constant post-GC live-JS residue pinning a whole subtree per component). Linking both reports.
- Android removes and deletes every view of an unmounted subtree inside the frame that unmounts it #59448 — DELETE+REMOVE are emitted per node for unmounted subtrees (
Differentiator.cpp); our registry traces confirm they are also executed on 0.83.6's pop path, so our retention sits downstream of deletion. (RemoveDeleteTreedeferred teardown was removed in Cleanup enableRemoveDeleteTreeInstruction experiment #45385.) - [PerformanceEntryKeyedBuffer growth (Performance timeline: PerformanceEntryKeyedBuffer never evicts entries (NativePerformance::reportMeasure → unbounded vector push_back) — retained across unmount and surface restart; +2.96 MB / 20 navigation cycles at 100% survival #60211) — a separate, separable retention class found in the same measurements (~148 KB/cyc, 100% immortal, disjoint fix site).]
- Fabric shadow subtrees of unmounted components using useSharedValue/useAnimatedStyle stay retained (native heap grows per screen visit) — reproduced on 4.5.1, 4.5.5 and 4.6.0 software-mansion/react-native-reanimated#10521 — real but scoped for this class (our comment there bounds its share); ruled out as the universal holder by the static-screen repro.
- rnscreens calling navigationBar's overridden ref function #3755 — ruled out for this class (our screen containers do not carry the retention).
Activity
react-native-bot commentedon Nov 22, 2026
Warning
Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:
You can read more about about it on our website: How to report a bug.