Skip to content

Fabric (Android, New Arch): unmounted host components' ShadowNodeWrapper set is never released — one popped screen's shadow subtree (createNode nodes + RawProps props) retained per navigation cycle; survives GC and stopSurface; ~1.0–1.5 MB/cycle #60210

Open

Description

@john-stalvern

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

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)

  1. SurfaceMountingManager.mTagToViewState does 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.
  2. 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).
  3. 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.
  4. Not tree-scoped (native probe + source walk). UIManager::stopSurface removes and destroys the ShadowTree (UIManager.cpp:265–294); ShadowTree holds a single currentRevision_ (ShadowTree.h:151 — no revision history); MountingCoordinator is single-slot (baseRevision_/lastRevision_). Native readouts at every rest: registryCount=1, node count flat (155); lockCount=0 captured=0 for LazyShadowTreeRevisionConsistencyManager::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=0 while 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.)
  5. Not a pure-C++ retainer: a live JS residue roots it. After 4× forced GC at each rest: js_allocatedBytes 8,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 survives unloadApp()+GC (10,354,120 ≈ c20). (Earlier "JS heap flat" readings were instrument-limited — the residue sits inside that instrument's ±1% band; post-forced-GC js_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.)
  6. Not Reanimated, not navigation. A static screen with zero react-native-reanimated/Animated imports reproduces the full slope (per-entry retention only 14.4 vs 11.7 KB/entry·cycle animated vs static — additive, not universal).
  7. Preallocated views bounded out at byte level. The createViewUnsafe ART 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 meminfo at c00/c05/c10/c15/c20 rest points, NH.Alloc slope; controls (bare-View screen) stay flat. Live-JS residue: HermesInternal.getInstrumentedStats().js_allocatedBytes after 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 useState toggling, 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:

  1. 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, commit 0411c43b3a, 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.
  2. An EventTarget/EventEmitter bookkeeping imbalance closing a per-component C++↔JS cycle: EventTarget::strongInstanceHandle_ is a strong JS root held from C++ while retainCount_ > 0 (EventTarget.h/.cpp), and EventEmitter::setEnabled is additive ("a number of enable calls should be equal to a number of disable calls to release the event target", EventEmitter.h:53–55), driven by ShadowNode::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

Activity

  1. added
    Needs: Repro
    on Nov 22, 2026
  2. react-native-bot commented on Nov 22, 2026

    @react-native-bot
    Collaborator

    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.

  3. john-stalvern commented on Nov 22, 2026

    @john-stalvern
    Author

    Reproducer PR opened to satisfy the missing-reproducer gate: #60215 — a self-contained RNTesterPlayground.js change (stock View/Text/local-Image subtree, 20 mount/unmount cycles with a fresh key per mount, optional global.gc()), no third-party dependencies.

    Measured on a locally built RNTester APK (main @ d6ea9fc, x86_64 emulator): Native Heap post-GC retention +0.097 MB/cycle with per-cycle GC, and a monotonically rising post-unmount floor (+0.68–0.80 MB/cycle) across all 20 cycles — the "sawtooth that never descends" described in the issue. Data in this class was also reproduced on 0.83.6 bridgeless (~1.0–1.5 MB/cycle).

  4. added
    Needs: Attention
    and removed on Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionNeeds: Repro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions