@mlabs-haskell/cardano-serialization-lib-gc

1.0.10 • Public • Published

cardano-serialization-lib-gc

This is a small ESM library that provides a wrapper for managing garbage collection for cardano-serialization-library. It does this by using a FinalizationRegistry object to keep track of objects that are no longer in use, and calling the free() method on them when they are finalized.

Three packages are provided:

  • @mlabs-haskell/cardano-serialization-lib-gc-nodejs
  • @mlabs-haskell/cardano-serialization-lib-gc-browser
  • @mlabs-haskell/cardano-serialization-lib-gc - a version for both NodeJS and the browser

Example usage with NodeJS:

const lib = require("@mlabs-haskell/cardano-serialization-lib-gc");

function fixture() {
  lib.PlutusData.new_bytes(
    new Uint8Array(Array(10000000).fill(0))
  );
}

setInterval(() => {
  for (let i = 0; i < 10; i++) {
    fixture()
  }
}, 500) // collection of unused objects will trigger `free()` calls
// for the corresponding WASM-allocated memory

This code will not leak, but if you try to use the original package, the memory usage will steadily grow.

If you want to use this library as a CommonJS module, use legacy csl-gc-wrapper instead.

Readme

Keywords

none

Package Sidebar

Install

npm i @mlabs-haskell/cardano-serialization-lib-gc

Weekly Downloads

39

Version

1.0.10

License

ISC

Unpacked Size

24.3 kB

Total Files

4

Last publish

Collaborators

  • amirmrad
  • klntsky
  • k.havryliuk
  • nalane
  • chase-mlabs
  • neil-mlabs