https://github.com/mlabs-haskell/cardano-serialization-lib-gc
cardano-serialization-lib with custom garbage collector for WASM
https://github.com/mlabs-haskell/cardano-serialization-lib-gc
Last synced: over 1 year ago
JSON representation
cardano-serialization-lib with custom garbage collector for WASM
- Host: GitHub
- URL: https://github.com/mlabs-haskell/cardano-serialization-lib-gc
- Owner: mlabs-haskell
- Created: 2023-07-25T12:17:12.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2024-11-18T16:38:02.000Z (over 1 year ago)
- Last Synced: 2025-03-24T09:19:49.260Z (over 1 year ago)
- Language: JavaScript
- Size: 41 KB
- Stars: 4
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cardano-serialization-lib-gc
This is a small ESM library that provides a wrapper for managing garbage collection for [cardano-serialization-library](https://github.com/Emurgo/cardano-serialization-lib). 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.
Example usage with NodeJS:
```javascript
import * as lib from "@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](https://github.com/mlabs-haskell/csl-gc-wrapper) instead.