Skip to content

Files

This branch is 268 commits behind AssemblyScript/assemblyscript:main.

rtrace

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 28, 2021
Oct 25, 2020
Jan 28, 2021
Mar 21, 2022
Feb 12, 2021
Jan 28, 2021
Jan 28, 2021
Jan 28, 2021
Mar 21, 2022

AssemblyScript Rtrace

A tiny utility to sanitize the AssemblyScript runtime. Records allocations and frees performed by the runtime and emits an error if something is off. Also checks for leaks.

Instructions

Compile your module that uses the full or half runtime with -use ASC_RTRACE=1 --exportStart _initialize and include an instance of this module as the import named rtrace.

const rtrace = new Rtrace({
  onerror(err, info) {
    // handle error
  },
  oninfo(msg) {
    // print message, optional
  },
  getMemory() {
    // obtain the module's memory,
    // e.g. using --exportStart:
    return instance.exports.memory;
  }
});

const { module, instance } = await WebAssembly.instantiate(...,
  rtrace.install({
    ...imports...
  })
);
instance.exports._initialize();
...

if (rtrace.active) {
  let leakCount = rtr.check();
  if (leakCount) {
    // handle error
  }
}

Note that references in globals which are not cleared before collection is performed appear as leaks, including their inner members. A TypedArray would leak itself and its backing ArrayBuffer in this case for example. This is perfectly normal and clearing all globals avoids this.