stable-memory

Persist Internet Computer canister data across upgrades using stable memory.

28|11|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/dfinity/icskills --skill stable-memory
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: stable-memory
Source: https://github.com/dfinity/icskills/tree/main/skills/stable-memory
Command: npx skills add https://github.com/dfinity/icskills --skill stable-memory

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the critical challenge of data loss in Internet Computer (IC) canisters when they are upgraded. It ensures that essential application state is reliably preserved across deployments.

Core Features & Use Cases

  • State Persistence: Guarantees that canister data survives upgrades by utilizing stable memory.
  • Upgrade Safety: Provides patterns and best practices to prevent common pitfalls that lead to data corruption or canister bricking during upgrades.
  • Motoko & Rust Support: Offers implementation examples for both major IC development languages.
  • Use Case: Essential for any canister managing user accounts, balances, or any form of persistent data that must remain available after a code update.

Quick Start

Use the stable-memory skill to add a user named 'Alice' to your canister's persistent storage.

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?

To persist canister state across upgrades on the Internet Computer, you must store data in stable memory. This Skill provides patterns using Rust's StableBTreeMap and Motoko's persistent actors to ensure data survival.

Why does heap memory disappear when upgrading my IC canister?

Heap memory disappears during IC canister upgrades because the runtime discards transient heap data when replacing code. Stable memory is specifically designed to survive these updates and prevent data loss.

How do I use StableBTreeMap and MemoryManager in Rust for canister data persistence?

You can achieve canister data persistence in Rust by implementing StableBTreeMap and MemoryManager. This Skill provides implementation examples to safely store and retrieve state across canister upgrades.

Does this Skill support persistent storage for both Motoko and Rust canisters?

Yes, this Skill supports persistent storage for both Motoko and Rust canisters. It offers implementation examples for Motoko's persistent actors and Rust's stable memory structures.

What causes data corruption or canister bricking during canister updates?

Data corruption or canister bricking during canister updates is typically caused by upgrade hook failures or improper state handling. This Skill provides best practices to avoid these pitfalls and ensure upgrade safety.

When do I need stable memory for my Internet Computer canister?

You need stable memory for your Internet Computer canister when managing user accounts, balances, or any persistent data that must remain available after a code update. It guarantees state persistence across deployments.