getAppMemoryMonitor

Resolves to an object for querying the app's memory usage and limits

import { getAppMemoryMonitor } from "@roku-sdk/runtime/app-memory-monitor";
getAppMemoryMonitor(): Promise<AppMemoryMonitor>

Description

Resolves to an object for querying the app's memory usage and limits.

This wraps the runtime's app memory monitor, the TypeScript counterpart of BrightScript's roAppMemoryMonitor, and exposes only its query methods. To react to memory warnings, use useAppMemoryMonitor instead.

Return values

A promise that resolves to the app's AppMemoryMonitor.

Example

const monitor = await getAppMemoryMonitor();
console.log(`Memory used: ${monitor.getMemoryLimitPercent()}%`);

Types

AppMemoryMonitor

The memory queries that getAppMemoryMonitor exposes to app code.

Each method reads the current value from the runtime when it is called. Memory warnings are not part of this object; subscribe to them with useAppMemoryMonitor.

type AppMemoryMonitor = {
    getMemoryLimitPercent: () => number;
    getChannelAvailableMemory: () => number;
    getChannelMemoryLimit: () => ChannelMemoryLimit;
    getTSHeapInfo: () => object;
};
NameTypeDescription
getChannelAvailableMemory() => numberReturns the amount of memory the app can still use before it reaches its limit, in kilobytes, matching GetChannelAvailableMemory on BrightScript's roAppMemoryMonitor.
getChannelMemoryLimit() => ChannelMemoryLimitReturns the app's memory limits: the maximum memory in the foreground, the maximum in the background, and the maximum for the Roku-managed heap.
getMemoryLimitPercent() => numberReturns how much of the app's memory limit is currently in use, as a percentage.
getTSHeapInfo() => objectReturns heap statistics from the JavaScript engine (Hermes) that runs the app. See below.

AppMemoryMonitor.getTSHeapInfo

Returns heap statistics from the JavaScript engine (Hermes) that runs the app.

The object's fields depend on the engine, so use it for diagnostics and logging rather than reading specific fields in app logic.


What’s Next

Did this page help you?