Created
June 24, 2011 11:34
-
-
Save richardms/1044613 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("node-proxy"), | |
fs = require('fs'), | |
util = require("util") ; | |
var count = 100000 ; | |
var handlerFactory = function () { | |
// Load something big: | |
var data = fs.readFileSync("/bin/ls") ; | |
return { | |
get: function (receiver, name) { | |
if (name === "length") { | |
return data.length ; | |
} | |
}, | |
getOwnPropertyDescriptor: function(name) { | |
var desc = undefined ; | |
if (name === "length") { | |
return Object.getOwnPropertyDescriptor(data, 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())) ; | |
} | |
count -= 1 ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried a scenario in this gist where I directly released the reference from the large object, but it did not have a mitigating effect on the heap size.