Global Lynx Memory Query
Use the global Lynx memory query when you need a current, one-shot snapshot of Lynx-attributed memory across live Lynx instances in the current process.
This API is designed for active diagnostics: memory pressure handling, quick high-memory triage, and deciding whether a deeper heap investigation is needed. It is not a high-frequency monitor and does not release memory by itself.
Monitoring And Data Availability
For new integrations on Android and iOS, use Lynx 4.4 or later. HarmonyOS support starts with Lynx 4.5. Earlier versions use the legacy behavior described below.
From Lynx 4.4, configure memory_monitor_config before creating pages or VMs. Use global_sample_rate,1,lynx_ui_sample_rate,1 when page-level BTS attribution and UI memory are required. UI collection remains conditional on lynx_ui_sample_rate. In Lynx 4.5, destroyed-page residual diagnostics also require monitoring.
What It Measures
The query reads available Element, UI/View, main-thread runtime (MTS), and background-thread runtime (BTS) memory from live Lynx instances in the current process. Its inventory and BTS attribution depend on the SDK version, as described above.
In Lynx 4.5, it also returns diagnostic records for destroyed pages with tracked BTS residuals. Without monitoring, the result includes available Element and runtime data; UI memory, page-level BTS attribution, and destroyed-page residuals are unavailable.
It differs from passive or periodic memory reporting: passive reporting is useful for dashboards and historical analysis, while this API asks the current process for a fresh snapshot at the moment the caller needs it.
It also differs from heap snapshots. Heap snapshots can prove JavaScript retainer chains. This query gives a fast memory inventory and points to the largest pages, instances, or categories.
To query only the current page from background JavaScript, use lynx.performance.getMemoryUsage(). That per-page API requires enabled memory monitoring; check its status before reading memory fields.
Native API
The following iOS and Android examples assume Lynx 4.4 or later. Check collectionStatus before using the totals.
iOS
Use the overload with timeoutMs to provide a timeout value:
For Lynx 4.5 and later, additionally check monitoring availability inside the callback:
Android
Use the overload with timeoutMs to provide a timeout value:
For Lynx 4.5 and later, additionally check monitoring availability inside the callback:
HarmonyOS
Available from Lynx 4.5:
Pass timeoutMs as the second argument when needed:
Omitting timeoutMs or passing a value <= 0 uses the default of 2000 ms. On Android and iOS in Lynx 4.3 and earlier, it limits the collection wait: a deadline can produce timeout with the instances collected so far. From Lynx 4.4, the native snapshot retains this value for API compatibility and does not enforce it as a collection deadline. HarmonyOS, introduced in Lynx 4.5, uses the same metadata behavior.
Result Fields
The tables use native numeric type names. HarmonyOS exposes numeric fields as number. The tables describe the common Android and iOS fields, with additions and behavior changes marked by SDK version. HarmonyOS exposes them from Lynx 4.5.
Global Result
Instance Result
Destroyed Instance Result
Available from Lynx 4.5 only:
For these records, HarmonyOS and DevTool JSON omit totalBytes, elementBytes, elementNodeCount, viewBytes, viewDetail, mainThreadRuntimeBytes, and backgroundThreadRuntimeBytes. Android and iOS retain the typed properties with zero or empty values. For live instance objects, the Android/iOS residual property is 0; HarmonyOS and DevTool JSON omit it.
Collection Semantics
- On Android and iOS, callbacks run on the Lynx report thread after native initialization. Dispatch to the main thread before touching platform View objects. On HarmonyOS, the callback returns to the calling ArkTS environment.
- In Lynx 4.3 and earlier, concurrent calls join the same in-progress collection. The selected fetchers are fixed at collection start. A timeout completes the request with available partial data.
- From Lynx 4.4, each call takes an independent native snapshot, and successful results have equal instance counts. The SDK retains
timeoutMsas metadata. - Lynx 4.5 includes unmonitored live instances and can query without enabling monitoring. Missing or destroyed engine actors can leave category values at
0; completion does not guarantee every source was available. - On Android, querying before native library initialization returns an empty completed result in Lynx 4.4 and an error in Lynx 4.5. An empty inventory on an older SDK does not establish that the process has no Lynx memory.
- With no selected live instances, a completed result has zero Lynx-attributed bytes. In Lynx 4.5 with monitoring enabled,
destroyedInstancesmay still contain diagnostics while a tracked shared VM survives; without monitoring, that list is empty. - An on-demand query does not enable monitoring, start monitoring timers, or produce periodic monitoring reports.
- From Lynx 4.4, global BTS memory counts each VM used by live instances once, by native VM identity. Different VMs with the same
btsRuntimeGroupIdremain distinct. Lynx 4.3 and earlier use the group-based aggregation described in the field table. - Lynx 4.5 destroyed-instance residuals are not added separately to totals. Residuals in a VM used by live instances are already part of its whole heap.
- Queries do not trigger GC. In Lynx 4.5, supported VM heaps are refreshed on their owning JS runners; page residuals come from the latest memory-monitor callback.
Interpreting The Result
Start with collectionStatus on every SDK version. An error result is a failed query, not evidence of zero memory. In Lynx 4.3 and earlier, treat timeout as partial data and compare completedInstanceCount with expectedInstanceCount before using the totals.
In Lynx 4.5 and later, also check errorMessage and memoryMonitoringEnabled. When monitoring is disabled, UI bytes and page-attributed BTS bytes are unavailable and returned as 0, and destroyedInstances is empty. Available whole BTS VM heaps still contribute to the global total. Older SDKs do not expose these diagnostic fields; verify monitoring in the host configuration.
Check collectionDurationMs and both instance counts, then compare totalBytes, appBytes, and ratioToApp. Keep the SDK version and monitoring/UI settings consistent across snapshots.
On Lynx 4.3 and earlier, a zero or empty result can reflect unregistered or unmonitored instances. On Lynx 4.4, it can reflect disabled monitoring, a process not selected by global_sample_rate, or an Android query made before native library initialization.
Instance BTS totals change meaning at Lynx 4.4, so a reduction across that upgrade alone does not establish a memory improvement.
Then compare category totals:
- High
elementByteswith highelementNodeCountpoints to Element tree or node-count growth. - High
viewBytespoints to platform UI/View weight. UseviewDetailto identify dominant view categories. - High global
mainThreadRuntimeBytesorbackgroundThreadRuntimeBytespoints to runtime memory. On Lynx 4.3 and earlier, instance BTS bytes describe the whole VM; from Lynx 4.4, they describe page attribution. In Lynx 4.5, compare that page component withbtsRuntimeTotalBytesand usebtsRuntimeTypeto identify the engine. A zero heap value can mean data is unavailable.
For lifecycle confidence on every version, take repeated queries before opening the target page, after reproducing high memory, and after exiting the page and allowing cleanup. On Lynx 4.3 and earlier, wait for each callback before the next query so that the observations do not share the same in-progress request. Compare instance membership, category bytes, and whether totals return toward the baseline. A page that remains in instances[] is still considered live; disappearance alone does not prove that all related memory was released.
In Lynx 4.5, a page in destroyedInstances[] has exited but still has tracked BTS bytes. Inspect backgroundThreadRuntimeResidualBytes and whether it persists or grows. These records are clues, not proof of a leak: the list is limited to five qualifying pages per shared QuickJS VM, and the query does not force GC.
For Lynx 4.5 and later, see Heap Snapshot Collection to capture MTS, page BTS components, or whole BTS VMs and inspect JavaScript retainer chains. For an exited page, pass its instanceId to takeBtsResidualHeapSnapshot.