Skip to content

system.getMemoryUsage

since 1.1.0

Return Ethos Memory Usage.

system.getMemoryUsage()

Parameters

None.

Returns

Table with elements:

  • mainStackAvailable (integer) Memory available for the main stack (bytes)
  • ramAvailable (integer) Memory available for the whole system (bytes)
  • luaRamAvailable (integer) Memory available for Lua scripts execution (bytes)
  • luaBitmapsRamAvailable (integer) Memory available for loading bitmaps in Lua scripts (bytes)

Examples

local mem = system.getMemoryUsage and system.getMemoryUsage() or {}
print(string.format("lua free %.1fkB, bitmaps free %.1fkB, stack free %.1fkB",
  (mem.luaRamAvailable or 0) / 1024,
  (mem.luaBitmapsRamAvailable or 0) / 1024,
  (mem.mainStackAvailable or 0) / 1024))

On current radios the Lua heap and bitmap memory come from one shared region, so treat the two numbers as one budget. Track the minimum stack seen, not single readings. See the memory monitor recipe and Saving RAM.

Used in

Real-world usage

Called 10 times across 3 open-source Ethos Lua projects. A few short excerpts:
local mem = system.getMemoryUsage and system.getMemoryUsage() or {}

src/rfsuite/tasks/background.lua:78

dashx.session.lastMemoryUsage = system.getMemoryUsage().luaRamAvailable

src/dashx/lib/utils.lua:590

local function memoryText()
  if not system or not system.getMemoryUsage then return "-" end
  local mem = system.getMemoryUsage() or {}
  return common.formatBytes(mem.ramAvailable or 0)
end

src/wfsuite/app/pages/diagnostics_rfstatus.lua:22