Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

smartptr

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

smartptr

Smart pointers for JavaScript/node.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

smartptr

Node module for a smart pointer

Usage

var smartptr = require('smartptr');

function FileHandle(name) {
  var fd = _open(name);
  this.handle = smartptr(fd, function (fd) {
    _close(fd);
  });
  console.log(this.handle.raw); // == fd
}

FileHandle.prototype = {
  close: function () {
    this.handle.release();
  },
};

var file = new FileHandle(name);
file = null;
global.gc();
// _close() will be triggered automatically

A word of caution

Smart pointers in JavaScript should be used very carefully. Relying on the GC to manage resources is in almost all cases a bad idea in theory, but can be a real life safer in practice.

You should make it a habit to release the smart pointer manually with release(), but if you forget to do so, smartptr will have your back.

Its strongly discouraged to rely on this. Think of it as a safety net, not a convenience.

Keywords

FAQs

Package last updated on 27 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc