https://github.com/shyiko/node-finalize-addon
Object finalization based on N-API for Node.js v8.6.0+
https://github.com/shyiko/node-finalize-addon
finalize n-api node-addon weak
Last synced: about 2 months ago
JSON representation
Object finalization based on N-API for Node.js v8.6.0+
- Host: GitHub
- URL: https://github.com/shyiko/node-finalize-addon
- Owner: shyiko
- License: mit
- Created: 2018-04-29T20:40:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-30T06:00:05.000Z (almost 8 years ago)
- Last Synced: 2025-02-20T20:46:53.544Z (about 1 year ago)
- Topics: finalize, n-api, node-addon, weak
- Language: C++
- Size: 15.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# node-finalize-addon [](https://travis-ci.org/shyiko/node-finalize-addon) [](https://www.npmjs.com/package/finalize-addon)
Object [finalization](https://en.wikipedia.org/wiki/Finalizer) based on [N-API](https://nodejs.org/api/n-api.html) 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
```sh
npm install finalize-addon
```
## Usage
```javascript
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()
```
> `require`ing 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) license.
Copyright (c) 2018 Stanley Shyiko.