
Product
Introducing Custom Tabs for Org Alerts
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.
slab-hunter
Advanced tools
Hunt down Buffer slabs which are retaining more memory than they should.
Warning: this is a debugging tool, do not use it in production code.
It detects two behaviours indicative of potential memory leaks:
Buffer.allocUnsafe() or Buffer.from() for long-lived buffers.b4a.allocUnsafeSlow() instead.Buffer.subarray() or similar, which does not copy out the data.Note: this tool works by monkey-patching Buffer.allocUnsafe to keep track of the state of every non-garbage-collected buffer, so memory usage and CPU will be higher than for a normal run.
npm i -g slab-hunter
slab-hunter <entrypoint>
Where <entrypoint> is the entrypoint of the program you wish to test.
For example:
slab-hunter index.js
Information about the potential leaks will be logged every 2 minutes.
const setupSlabHunter = require('slab-hunter')
const getLeakStats = setupSlabHunter()
setInterval(() => {
console.log(getLeakStats())
}, 1000 * 60 * 2)
Big buffer potential leaks:
1 leaks of big buffers of avg size 8.4 MB (total: 8.4 MB) at Object.allocUnsafe (.../node_modules/b4a/index.js:14:17)
at NoiseSecretStream._onrawdata (.../node_modules/@hyperswarm/secret-stream/index.js:254:33)
at UDXStream.emit (node:events:513:28)
at UDXStream.emit (node:domain:489:12)
at ReadableState.drain (.../node_modules/streamx/index.js:351:64)
at ReadableState.update (.../node_modules/streamx/index.js:361:12)
at ReadableState.updateReadNT (.../node_modules/streamx/index.js:543:10)
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
...
Slab retainers potential leaks:
2013 leaks of avg 8.1 kB (total: 1.6 MB normalised against retainers) at Object.allocUnsafe (.../node_modules/b4a/index.js:14:17)
at UDXStream._allocWrite (.../node_modules/udx-native/lib/stream.js:430:26)
at UDXStream._writev (.../node_modules/udx-native/lib/stream.js:273:23)
at WritableState.autoBatch (.../node_modules/streamx/index.js:175:12)
at UDXStream._write (.../node_modules/streamx/index.js:947:25)
at WritableState.update (.../node_modules/streamx/index.js:187:16)
at WritableState.updateWriteNT (.../node_modules/streamx/index.js:550:10)
at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
...
Total potential big buffer leaks: 10.7 MB
Total potential slab-retainer leaks: 3.7 MB
const getLeakStats = setupSlabHunter(msLeakCutoff=1000*60, bigBufferCutoff=4000)Returns a function to get the current potential leaks.
msLeakCutoff is the amount of milliseconds until a buffer is tagged as potentially leaking (meaning it will be included in the analysis).
bigBufferCutoff is the amount of bytes from which point onwards a buffer is included in the 'big-buffer analysis'.
getLeakStats is a function which returns a LeakOverview object. The object can be printed to see a complete overview, but can also be accessed programatically.
Note: the total size of a slab-retainer leak is calculated by normalising each leak against the amount of other retainers for that slab (their normalisedTotalLeakedBytes value). So if a single 8kb slab is retained by 10 small buffers, each of those will report around 800 bytes leaked.
leakOverview.bigBufferLeaksReturns a list of big-buffer leaks. Each entry is an object:
{
location, // The stack trace where the leaking buffer was created (this is the unique key for this leak)
amount, // the amount of leaks created at the location
totalLeakedBytes // the total amount of leaked bytes (summed across all its ocurrences)
}
leakOverview.slabLeaksReturns a list of slab leaks. Each entry is an object:
{
location, // The stack trace where the leaking buffer was created (this is the unique key for this leak)
amount, // the amount of leaks created at the location
totalLeakedBytes // the total size of the leak (summed across all its ocurrences).
normalisedTotalLeakedBytes // the total size of the leak (summed across all its ocurrences), normalised against the amount of other retainers of the slabs
}
FAQs
Detect Buffer slabs indicative of a memory leak
We found that slab-hunter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers 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.

Product
Create and share saved alert views with custom tabs on the org alerts page, making it easier for teams to return to consistent, named filter sets.

Product
Socket’s Rust and Cargo support is now generally available, providing dependency analysis and supply chain visibility for Rust projects.

Security News
Chrome 144 introduces the Temporal API, a modern approach to date and time handling designed to fix long-standing issues with JavaScript’s Date object.