stable-memory

Persist Internet Computer canister state across upgrades using StableBTreeMap and StableCell.

Updated Dec 18, 2025
One-click install
npx skills add https://github.com/Looping-AI/looping-control-plane --skill stable-memory-looping-ai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: stable-memory
Source: https://github.com/Looping-AI/looping-control-plane/tree/main/.agents/skills/stable-memory
Command: npx skills add https://github.com/Looping-AI/looping-control-plane --skill stable-memory-looping-ai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Stable memory persists canister state across upgrades, addressing data loss when canisters are redeployed and the heap memory is reset on upgrade.

Core Features & Use Cases

  • Persistent storage across upgrades via StableBTreeMap, StableCell, and MemoryManager.
  • Language support for Motoko and Rust with upgrade hooks and safe serialization patterns.
  • Use case: preserving user data, counters, and configuration across upgrades without migration.

Quick Start

Initialize a stable memory structure, add data, then upgrade to verify persistence.

Frequently Asked Questions about stable-memory

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I persist canister state across upgrades on the Internet Computer?

Stable memory persists canister state across upgrades by using StableBTreeMap, StableCell, and MemoryManager to store data outside the heap, preventing data loss when canisters are redeployed on the Internet Computer.

Why does my canister lose data when I redeploy or upgrade?

Canisters lose data on upgrade because heap memory is reset during redeployment. You need stable memory structures like StableBTreeMap to preserve user data, counters, and configuration across upgrades without requiring manual migration.

Does stable memory work with both Motoko and Rust canisters?

Stable memory integration supports both Motoko and Rust canisters, providing upgrade hooks and safe serialization patterns to ensure durable storage across upgrades in either language environment.

How do I initialize and verify stable memory persistence?

Initialize a stable memory structure like StableBTreeMap, add your data, then upgrade the canister to verify that the data persists successfully across the redeployment without loss.

What's the best way to safely migrate canister data during an upgrade?

The best way to safely migrate canister data during an upgrade is to use stable memory structures with proper upgrade hooks and safe serialization patterns, ensuring persistent storage via MemoryManager and StableBTreeMap.

When do I need to use MemoryManager for canister storage?

You need MemoryManager when your canister requires durable storage across upgrades and uses multiple stable memory structures, as it manages memory allocation for StableBTreeMap and StableCell to safely persist state.