I have a question about callbacks. I have an object which one function is used as a setTimeout callback and that object can be deleted before the callback fires. Will node know not to call it when timeout occurs or will it keep a reference and call it anyway?
Did some tests and it looks like node keeps a reference to the object and fires the callback.
After "delete" the object is not necessarily deleted, you are only deleting your reference of it. The method will still be callable.
> cat test.js
var a = {
method: function() {
console.log('a' + a.property)
},
property: '1'
}
setTimeout(a.method, 1000);
delete a;
> node test.js
a1