Part 9 · Best practices

Hermes memory: JS heap is only part of the story

Prerequisites: 01-hermes-pipeline, 05-hermes-jsi

Two memory domains

Separate observations. The diagram does not imply a one-to-one allocation mapping. Nodes: Hermes heap, Host object, Native heap, JS snapshot, Platform profiler.
Separate observations. The diagram does not imply a one-to-one allocation mapping. [S04] [S13] [S14]

Mental model synthesis

Hermes owns JS values and reclaims unreachable JS objects. A JSI host object can reference a separate native resource; a JS heap snapshot alone cannot account for every native allocation. React Native DevTools can inspect the JS heap, while platform tools are needed beneath it.

[S04] [S13] [S14]

Worked diagnosis synthesis

A gallery grows 20 MB after each open/close. Compare JS heap snapshots, Android Studio/Xcode native memory, and the number of retained image contexts. A stable JS heap plus growing native allocation points toward the native resource path, not proof of a GC defect.

[S13] [S14]

Engineering decision synthesis

Define resource release at unmount, module destruction and cancellation. Avoid retaining callbacks and long-lived handles without an owner. Measure steady-state after repeated navigation.

[S12] [S13] [S14]

Failure mode and improvement synthesis

Calling GC manually is not a substitute for fixing a retained reference. Trace object ownership and eliminate the root; rerun the same loop to establish whether memory plateaus.

[S13] [S14]
Keep this: Separate JS heap growth from native allocation and resource retention before blaming GC.
Check yourself: Would a flat JS heap rule out a native image leak?

No. Native buffers and platform views can grow outside the JS heap.

Sources & further reading

  1. [S04] About the New Architecture

    React Native · official documentation or maintainer source · accessed 2026-10-09 · current documentation as accessed; examples conceptual

    Supports: JSI references, module and renderer interoperability, limits of performance claims.

    Inspect the implementation boundary described by this source.

  2. [S12] Module API Reference

    Expo · official documentation or maintainer source · accessed 2026-10-09 · current documentation as accessed; examples conceptual

    Supports: Function, AsyncFunction, queues, views, events and lifecycle.

    Inspect the implementation boundary described by this source.

  3. [S13] Using shared objects

    Expo · official documentation or maintainer source · accessed 2026-10-09 · current documentation as accessed; examples conceptual

    Supports: Long-lived native instances, JS references and deallocation.

    Inspect the implementation boundary described by this source.

  4. [S14] React Native DevTools

    React Native · official documentation or maintainer source · accessed 2026-10-09 · current documentation as accessed; examples conceptual

    Supports: JS traces, heap snapshots and React profiling; native tools still needed.

    Inspect the implementation boundary described by this source.