Skip to content

Instantly share code, notes, and snippets.

@richardms
Created June 24, 2011 11:34
Show Gist options
  • Save richardms/1044613 to your computer and use it in GitHub Desktop.
Save richardms/1044613 to your computer and use it in GitHub Desktop.
Possible memory leak in node-proxy
// 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 ;
}
@samshull
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment