Skip to content

Object finalization based on N-API for Node.js v8.6.0+

License

Notifications You must be signed in to change notification settings

shyiko/node-finalize-addon

Repository files navigation

node-finalize-addon Build Status npm

Object finalization based on N-API for Node.js v8.6.0+.
In a nutshell, it allows you to register a callback which will be executed when/if observable object becomes eligible for garbage collection.

Installation

npm install finalize-addon

Usage

const finalize = require('finalize-addon')
const finalizeCallback = () => {
  // warn if fd/sockets are left open, etc
}

function main () {
  const obj = ...
  finalize(obj, finalizeCallback)
}

main()
// obj is now eligible for garbage collection 
// (un-comment line below to force gc to run (requires `node --expose-gc`))
// gc() 

requireing N-API addon in Node.js < v10.0.0 results in Warning: N-API is an experimental feature and could change at any time.. Use NODE_NO_WARNINGS=1 node ... or node --no-warnings ... to suppress.

License

All code, unless specified otherwise, is licensed under the MIT license.
Copyright (c) 2018 Stanley Shyiko.

About

Object finalization based on N-API for Node.js v8.6.0+

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published