Skip to content

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

Notifications You must be signed in to change notification settings

silklabs/node-managed-resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

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).

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!'

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published