-
-
Save samshull/1045387 to your computer and use it in GitHub Desktop.
Possible memory leak in node-proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run with: | |
// node --trace-gc proxy_memleak.js | |
var Proxy = require("/Users/brickysam26/Projects/node-proxy/lib/node-proxy"), | |
// fs = require('fs'), | |
util = require("util") ; | |
var count = 100000 ; | |
var handlerFactory = function () { | |
// Load something big: | |
var data = { | |
file: Array(80202).join('x') // fs.readFileSync("/bin/ls", "utf8") | |
}; | |
return { | |
get: function (receiver, name) { | |
if (name === "length") { | |
return data.file.length ; | |
} | |
if (name === "cleanup") { | |
return (delete data.file); | |
} | |
}, | |
getOwnPropertyDescriptor: function(name) { | |
var desc = undefined ; | |
if (name === "length") { | |
return Object.getOwnPropertyDescriptor(data.file, name) ; | |
} | |
return desc; | |
}, | |
getOwnPropertyNames: function() { | |
return ["length"] ; | |
}, | |
defineProperty: function(name, propertyDescriptor) { | |
}, | |
"delete": function(name) { | |
}, | |
fix: function() { | |
// As long as this.obj is not frozen, the proxy won't allow itself to be fixed | |
return undefined; // will cause a TypeError to be thrown | |
} | |
} ; | |
} ; | |
while (count > 0) { | |
var proxy = Proxy.create(handlerFactory()) ; | |
if ((count % 1000) === 0) { | |
util.debug("length: "+proxy.length+" "+JSON.stringify(process.memoryUsage())) ; | |
} | |
if (!proxy.cleanup) { throw "Cleanup failed"; } | |
count -= 1 ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment