Motoko - Get Canisters Sizes / Limits

Is there a way to introspect canister size / limits from Motoko at the moment?

1 Like

Hi Hazel,

There no official library at the moment, but if you are desperate, and with the caveat that these APIs may change, there’s some basic stats provided but the Prim (pseudo) library:

rts_version : () -> Text 
rts_memory_size: () -> Nat;
rts_heap_size: () -> Nat;
rts_total_allocation: () -> Nat;
rts_reclaimed : () -> Nat;
rts_max_live_size : () -> Nat;

(Sizes are in bytes.)

You can access Prim with a special import (as do many base libraries):

import Prim "mo:prim";


The Prim module is not intended to be accessed by users but is used to implement motoko-base. It’s API is liable to change so use at your own risk/discretion.

Note that Motoko currently uses a 2-space copying collector so the heap will be at most half the memory, and the heap is thus bounded by 2GB. We have another, compacting, GC in the pipeline that will allow access to much more of the 4GB for the heap.

Hope that helps,


Thanks @claudio! This is perfect! Noted the instability, this works just fine for my hacks / POC stuffs.

1 Like