← All tasks
javascriptcosmiconfig/cosmiconfig #90Not a task: not reproduced

JS config never gets garbage collected.

envgap__cosmiconfig__cosmiconfig-90

01 / FAILURE SIGNATURE

As reported upstream

No identifying execution failure has been captured.
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
1b38322c08163d2951775539a5debe1b5d1ba59a
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

cosmiconfig/cosmiconfig #90 · read the original issue
I discovered this issue while trying to catch a memory leak in our build tool. The way cosmiconfig loads '.js' config prevents it from ever getting garbage collected, even if userland code no longer needs. `require-from-string` package [creates a new `Module` record](https://github.com/floatdrop/require-from-string/blob/master/index.js#L24) which then permanently stored in memory. You can see it with this sample:



```js

const cosmiconfig = require('cosmiconfig');



const loadRC = require.resolve('cosmiconfig/lib/loadRc.js');



function loadOnce() {

    const explorer = cosmiconfig('example');

    return explorer.load(__dirname)

        .then(() => console.log(require.cache[loadRC].children.length))

}



let count = 1000;

function loop() {

    if (count > 0) {

        count--;

        loadOnce().then(loop);

    }

}



loop();

```



Provided there is a non-empty `example.config.js` nearby, you should see that `require.cache[loadRC].children.length` grows by 1 after every load and never gets cleaned up.
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]