Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #81

Open
yangyaochia opened this issue Sep 17, 2020 · 0 comments
Open

Memory leak #81

yangyaochia opened this issue Sep 17, 2020 · 0 comments

Comments

@yangyaochia
Copy link

yangyaochia commented Sep 17, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant