Skip to content

Calls a function when V8 collects an object as garbage

License

Notifications You must be signed in to change notification settings

charmander/gc-listen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gc-listen

A way to attach a JavaScript function with napi_add_finalizer. For debugging.

const gcListen = require('gc-listen');

const obj = {};

const callback = () => {
    // …
};

gcListen(obj, callback);

callback won’t be called as long as obj isn’t eligible for garbage collection. N-API even suggests it will be called when obj is collected. It will always be called asynchronously when called at all.