Woodya/node-gzbz2 — Issue #6: Memory leaks
Author: OrangeDog
Created: 2011-10-31 17:53:03+00:00
State: open

var gzbz2 = require("./gzbz2");
var data = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';

doTest();

function doTest() {
// log usage
console.log(process.memoryUsage().rss);

// make a new instance
var gzip = new gzbz2.Gzip;
gzip.init({level:3});

// call deflate more than once
gzip.deflate(data);
gzip.deflate(data);
gzip.end();

// clean up the V8 heap
gzip = undefined;
gc();

// loop forever
process.nextTick(doTest);
}

Call it as ```node --expose_gc leak.js``` and watch the memory usage grow...

Got this from valgrind as well

16,385 bytes in 1 blocks are definitely lost in loss record 48 of 51
at 0x4C2815C: malloc (vg_replace_malloc.c:236)
by 0x4C281D6: realloc (vg_replace_malloc.c:525)
by 0x2B63F161: Gzip::GzipDeflate(v8::Arguments const&) (compress.cc:80)
by 0x56D7A3: ??? (in /usr/local/bin/node)

Gzip doesn't appear to leak if ```deflate``` is called only once.
Bzip leaks regardless of how many times you call it.