I’m planning to move my canister’s heap memory from 32-bit to 64-bit with orthogonal persistence, and after doing so the stable keyword in Motoko will no longer be using stable memory for serialization/deserialization to & from stable-memory during an upgrade, as the data will remain in heap memory.
As I’m no longer using stable memory, I’d like to free up/zeroize my canister’s stable memory. Does this check/freeing happen automatically during upgrades, or is there a specific system API I can hook into in order to do this?
In case this doesn’t exist yet, it might be nice to look into accessible ways to free up canister memory. Especially since there are several subnets where the resource reservation mechanism has kicked in (they hold more than 450GB of state), and cycle costs for canister memory allocation increase past this point.
This is a sensible request but the ICO system API doesn’t support it, so Motoko can’t either.
Historically this is because the stable memory API was meant to be a temporary abstraction for a second wasm memory and wasm memories can only grow not shrink.
Ah, interesting to note that stable memory was originally intended as a temporary abstraction.
Are a canister’s heap memory and stable memory decoupled, separate wasm instances, or are they part of the same wasm?
Would it be possible to have a higher level memory manager and just zeroize that memory and kill that stable memory piece or allow it in some way to be reclaimed/reusable by the host?
I always felt that modelling memory as “only growable” in a general purpose runtime (spec for a runtime/VM?) was such a short sighted decision.
It definitely does not reflect the real world, where hardware memory is static inside a computer and not infinitely growable/swappable for more
Like what are devs expected to do?
Uninstall and reinitialize their application everytime they want to free up memory? Quite impractical
As a side note, if WASM doesn’t intend to provide this functionality, maybe the IC should consider supporting a mechanism to free up memory, maybe as an extension to Wasmtime?