WASM Heap allocated never cleared

Dropping memory

Make sure your code is dropping memory. WASM lets you reallocate memory, so you need to drop the memory in your code.

struct X(u32);

impl X {
    fn drop(self) {}
}

fn main() {
    let x = X(10);

    // Usually x goes out of scope and would get dropped.
    // But we can drop it here to profile memory.
    // Remember the allocation of WASM happens in chunks so
    // we want to see if we be deallocating appropriately for reuse 
    // by watching if a memory growth happens
    x.drop();
}

Allocator freed pages

Some allocators can be optimized to not return freed pages to the WebAssembly engine/operating system. Make sure your allocator is reallocating appropriate to your needs. Rust default allocator allows reuse of memory with WebAssembly, for example.