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

gc-hacks

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

gc-hacks

Collection of ugly hacks, for JS garbage collector. Use only as a last resort.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

gc-hacks

Collection of ugly hacks, for JS garbage collector. Use only as a last resort.

Code based on disscussion from this thread. And I higly recomend to read it before using this module.

Big thanks to @adamhooper for code suggestion and great advice:

And don't use these workarounds normally. Only use them when you have identified a problem and you are certain this fixes the problem, and you have commented why it fixes the problem.

Installation

npm install gc-hacks

Usage

var gcHacks = require('gc-hacks');

var veryLongString = 'xxxxxxxxxxxxxxxxxxxxx...';
var partString = veryLongString.substr(1);

// Now 'veryLongString' stuck in memory until `partString` exist
// or we can do force 'partString' to be copied.
partString = forceStringCopy(partString);

// But what if string inside object or array, like this:
var array = [veryLongString.substr(1)];

// Just use 'recreateObject' it work with any JSON-compatible value
array = recreateValue(array);

// Sometime GC don't free memory for long time.
// But you can force it if you run this function:
gcHacks.gcCollect();
// Note: you need to run node with '--expose-gc' argument.

// You can also wrap any function to do both hacks:
var hackedFunction = gcHacks.recreateReturnObjectAndGcCollect(someFunction);

// Or use it with promises:
somePromise
  .then(gcHacks.recreateReturnObjectAndGcCollect(function (arg1, arg2) {
    return [veryLongString.substr(1)];
  })

Keywords

FAQs

Package last updated on 23 Mar 2016

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