Universal Tuya docsHomeSupported devicesRequest a deviceFAQChangelogArchitectureKnowledge baseCreditsSourcesContributing

P2914 — App memory crashes (20/10/2026)

Evidence

Measurement (scripts/ci/memory-budget.js, SDK stubbed, --expose-gc)

Code + static data heap before any device event, app.js plus all drivers:

branchbefore P2914after P2914
master26.8 MB (1375 modules)26.5 MB (1353)
stable-v525.2 MB (1343)25.1 MB (1321)
bastien-home26.0 MB (1336)25.8 MB (1314)

That is about 40 % of the 64 MB budget, used before the first device event. Biggest inclusive costs: BaseUnifiedDevice 6.8 MB (shared by every Zigbee base), TuyaZigbeeDevice 3.8 MB to 3.1 MB, DeviceIOFacade 1.9 MB, OTAUpdateManager 0.95 MB, tuyapi 0.86 MB, TuyaUDPDiscovery 0.5 MB.

Fixes (additive, no couple or capability touched)

  1. Resilience registry leak. ZigbeeResilience.attach() puts each device in a module-level Set ticked by one shared interval. BaseUnifiedDevice attached again on every node init without detaching the old entry, and only onDeleted detached it, not onUninit. Re-interviews and app restarts therefore left dead device objects pinned and ticking. Now the old entry is detached before attaching, and TuyaZigbeeDevice.onUninit detaches too.
  2. Lazy tuyapi in TuyaLocalClient: loaded on the first WiFi connect.
  3. Lazy http/https in NetworkResilience, and lazy NetworkResilience in TuyaZigbeeDevice, which only uses it on the Enigma report path.

Guards

Next levers (not done, would change startup behaviour)

P2915: load simulation, lazy OTA/UDP, flow card ids (20/10/2026)

Simulated load (scripts/ci/load-heap-sim.js, 150 devices of 5 drivers, 100 events each, then delete all)

branchafter initafter events: before → afterafter delete: before → afterintervals left
master27 MB41.2 → 32.140.9 → 22.4150 → 0
stable-v526.3 MB40.0 → 31.239.6 → 21.6150 → 0
bastien-home26.4 MB40.0 → 31.739.9 → 22.1150 → 0

Top retainers in the snapshot, before the fixes

Lazy OTA and WiFi UDP discovery

Flow card ids

← Knowledge base index · source