When should I call the free() methods generated by wasm-pack?

Viewed 37

I wrote some Rust code and compiled it with wasm-pack. I notice these free() methods in the generated .d.ts files:

export class PdfDoc {
  free(): void;
  ...
}

PdfDoc owns a massive amount of memory, up to 1GB, so it's important that all that memory be properly released for reuse when the javascript code is done with it.

Questions:

  • When should I call these free() methods?
  • Do I need to call them explicitly or will they be called automatically?
  • What happens if I never call them?

I searched for "wasm-pack free method" but these combination of search terms didn't find anything useful.

0 Answers
Related