stable-memory

Installation
SKILL.md

Stable Memory & Canister Upgrades

What This Is

Stable memory is persistent storage on Internet Computer that survives canister upgrades. Whether ordinary variables survive depends on the language:

  • Rust -- heap data (thread_local! { RefCell<T> }, plain statics) is wiped on every upgrade. Any data you care about must live in stable memory, either through ic-stable-structures or by serializing it yourself in pre_upgrade/post_upgrade.
  • Motoko -- enhanced orthogonal persistence is on by default, so let and var in a persistent actor already survive upgrades with no stable keyword and no upgrade hooks. Only transient declarations are wiped.

Prerequisites

  • For Motoko: mops with core = "2.0.0" in mops.toml, and moc >= 1.7.0 (dot notation on Map/List needs it)
  • For Rust: ic-stable-structures = "0.7" in Cargo.toml

Canister IDs

No external canister dependencies. Stable memory is a local canister feature.

Mistakes That Break Your Build

  1. Using thread_local! { RefCell<T> } for user data (Rust) -- This is heap memory. It is wiped on every canister upgrade. All user data, balances, settings stored this way will vanish after icp deploy. Use StableBTreeMap instead.
Installs
271
GitHub Stars
34
First Seen
Mar 4, 2026
stable-memory — dfinity/icskills