# managed-resource

> Objects deriving from this class will invoke a destructor callback before being garbage-collected.

Latest version **0.0.3** (published 2016-12-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install managed-resource
pnpm add managed-resource
yarn add managed-resource
bun add managed-resource
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-12-19 |
| First published | 2016-12-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.4.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Andreas Gal |
| Maintainers | andreasgal |
| Keywords | gc |

## Links

- npm: https://www.npmjs.com/package/managed-resource
- Repository: https://github.com/silklabs/node-managed-resource
- Homepage: https://github.com/silklabs/node-managed-resource#readme
- Issues: https://github.com/silklabs/node-managed-resource/issues
- npm.io page: https://npm.io/package/managed-resource

## Dependencies (1)

- [weak](https://npm.io/package/weak.md) ^1.0.1

## Recent versions

- 0.0.3 (latest) — 2016-12-19
- 0.0.2 — 2016-12-19
- 0.0.1 — 2016-12-19

## README

# Managed-Resource
Any object allocated from this class or a class derived from it will
invoke the supplied destructor right before node garbage collects
the object.

The supplied handle is stored in the object (this.ref).

```JavaScript
const Resource = require('managed-resource');

function alloc() {
}

function free(handle) {
  console.log('free!');
}

class Test extends Resource {
  constructor(handle) {
    super(() => handle, (handle) => {
      free(handle);
    });
  }
};

let x = new Test(alloc());
console.log(x.ref);
gc(); // this will print 'free!'
```

---
_Source: https://npm.io/package/managed-resource · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
