chad3814 / node-hashtable

Native hashtable interface for when V8 objects can't take the heat
MIT License
106 stars 41 forks source link

Get and Has method not releasing memory #20

Closed vigbk closed 9 years ago

vigbk commented 9 years ago

When I use the get or has function and then call clear, for some reason the keys are still getting retained. This is a sample code i used to test var heapdump = require('heapdump'); var Hashtable = require('hashtable'); function putItems() { var hashtable = new Hashtable(); for(var i =0;i<1000000;i++) { var phoneNumber = 1000000000 + i; var strPhoneNumber = "+01" + phoneNumber.toString(); var frequency = hashtable.has(strPhoneNumber); if(!frequency) { hashtable.put(strPhoneNumber,1); }

}
console.log("1 million items");
heapdump.writeSnapshot('./memory_leak' + Date.now() + '.heapsnapshot');
hashtable.clear();
heapdump.writeSnapshot('./memory_leak' + Date.now() + '.heapsnapshot');

}

putItems();

When i comment out the has function then the memory gets completely released(The same if i replace has with get). I used node heap dump for debugging. Using node v0.12.4.

vigbk commented 9 years ago

I did a pull request with a fix. Let me know if there are any issues with that.

chad3814 commented 9 years ago

ugh, I haven't maintained this package (migrated everything to es6-native-map). There are certainly leaks in this version. I'll look at your PR and try to fix some other leaks (and probably make a node 0.12/iojs version).

vigbk commented 9 years ago

Sure. That would be great. Thanks.