kevva / decompress

Extracting archives made easy
MIT License
415 stars 51 forks source link

Memory leak #81

Open yangyaochia opened 4 years ago

yangyaochia commented 4 years ago

I tried to execute the following code, and observe the potential memory leak due to the decompress operation.

`

"use strict";

let path = require("path"); const decompress = require('decompress') let fs = require("fs");

const used = process.memoryUsage(); for (let key in used) { console.log(Memory: ${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB); }

let source = path.join(dirname + "/example.zip"); let output = path.join(dirname,"output")

decompress("./example.zip", "dist").then((files) => { console.log("decompress completed") console.log("-------------------------------") const used = process.memoryUsage(); for (let key in used) { console.log(Memory: ${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB); } global.gc(); console.log("after garbage collection") process.nextTick(function () { console.log("after tick") const used = process.memoryUsage(); for (let key in used) { console.log(Memory: ${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB); } });

setTimeout(function () {
    console.log("after timeout")
    const used = process.memoryUsage();
    for (let key in used) {
        console.log(`Memory: ${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
    }
}, 5000);

}) `

node --expose-gc decompress.js Memory: rss 25 MB Memory: heapTotal 12.73 MB Memory: heapUsed 6.64 MB Memory: external 0.09 MB decompress completed

Memory: rss 4275.02 MB Memory: heapTotal 12.23 MB Memory: heapUsed 5.39 MB Memory: external 3515.56 MB after garbage collection after tick Memory: rss 1764.59 MB Memory: heapTotal 12.23 MB Memory: heapUsed 5.38 MB Memory: external 1732.47 MB after timeout Memory: rss 1764.61 MB Memory: heapTotal 12.23 MB Memory: heapUsed 5.39 MB Memory: external 1732.47 MB