-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_garbageCollector leaks if keep is false #48
Comments
@raszi ^ |
remove object from _removeObjects if cleanup fn is called fixes #48
This should be reopened. It still leaks when Here's an example which demonstrates the leak. First, add an else clause to function _prepareRemoveCallback(removeFunction, arg) {
var called = false;
return function _cleanupCallback() {
if (called) return;
var index = _removeObjects.indexOf(removeFunction);
if (index >= 0) {
console.log("removing from _removeObjects");
_removeObjects.splice(index, 1);
} else {
console.log("_removeObjects.length = [" + _removeObjects.length + "]");
}
called = true;
removeFunction(arg);
};
} Then run the following: var tmp = require('tmp');
var fs = require('fs');
var createTempFile = function() {
tmp.file({ prefix : 'tmp_memory_leak_test_', postfix : '.txt', keep : false },
function(err, tempFilePath, tempFileDescriptor, tempFileCleanupCallback) {
if (err) {
console.log("Error trying to create the temp file. Will attempt cleanup.");
tempFileCleanupCallback();
}
else {
fs.writeFile(tempFilePath,
"Hello world, the current time is: " + Date.now() + "\n",
function(err) {
if (err) {
console.log("Error trying to write the file. Will attempt cleanup.");
tempFileCleanupCallback();
}
else {
tempFileCleanupCallback();
setTimeout(createTempFile, 1);
}
});
}
});
};
createTempFile(); You'll see that |
@chrisbartley bummer, but, it is rather late right now, I will have a look at this tomorrow evening 😄 |
@chrisbartley having run some tests in the REPL with the extracted _prepareRemoveCallback function yields no errors, the _removeObjects array gets cleaned up properly. Will try again tomorrow evening with a proper test case. |
_removeObjects never gets cleaned up if you call a cleanup function. it only ever gets appended to, this causes leaks for long lived processes that create many temporary file/dirs. when cleanup functions are called they should remove their temp file from _removedObjects.
the workaround right now is to always set
keep:true
and assume you are doing cleanup yourselfThe text was updated successfully, but these errors were encountered: