
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
garbage-collector
Advanced tools
A garbage collector built on top of typed arrays.
A simple reference counting Garbage Collector built for use with malloc.
Install via npm.
npm install garbage-collector
import Allocator from "malloc";
import GarbageCollector from "garbage-collector";
const heap = new Buffer(1024 * 1024);
const allocator = new Allocator(heap); // heap could also be an ArrayBuffer
const gc = new GarbageCollector(allocator, {
// The number of cycles before an item with no references will be freed.
lifetime: 2,
// The callbacks which will be invoked when a tagged block is freed.
// Keys must be integers within uint32 range, greater than zero.
callbacks: {
1: (offset) => {
console.log('Freeing string at', offset);
}
}
});
console.log(gc.inspect());
const input = "Hello World";
const offset = gc.alloc(Buffer.byteLength(input), 1); // 1 is the type tag, it's optional.
heap.write(input, offset);
gc.ref(offset); // increment the reference count
gc.cycle(); // our data is preserved because it has a reference count > 0
console.log(gc.inspect());
console.log(gc.sizeOf(offset));
gc.unref(offset); // decrement the reference count by 1
const freed = gc.cycle(); // frees our string and invokes the callback
console.log('freed', freed, 'bytes');
Published by codemix under a permissive MIT License, see LICENSE.md.
FAQs
A simple garbage collector built on top of typed arrays.
We found that garbage-collector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.