rspack icon indicating copy to clipboard operation
rspack copied to clipboard

Memory leak when using `@rspack/core` API

Open Nikaple opened this issue 1 year ago • 8 comments

System Info

  System:
    OS: Linux
    CPU: (16) x64 Intel(R) Xeon(R) Platinum 8255C CPU @ 2.50GHz
    Memory: 19.11 GB / 31.10 GB
    Container: Yes
    Shell: 5.0.2 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  npmPackages:
    @rspack/cli: latest => 0.1.10 
    @rspack/core: ^0.1.10 => 0.1.10 

Details

screenshot

With webpack

screenshot-webpack

Reproduce link

No response

Reproduce Steps

  1. Create a project npm create rspack@latest
  2. Create a script to compile consecutively with @rspack/core
  3. Run the script to get memory leak

Script content:

const { rspack } = require('@rspack/core')
const config = require('./rspack.config')

function compile() {
    const compiler = rspack(config);
    return new Promise((resolve, reject) => {
        compiler.run((err, stat) => {
            if (err) {
                return reject(err)
            }
            return resolve(stat)
        })
    })
}


async function main() {
    await compile();

    setTimeout(() => {
        const memory = process.memoryUsage();
        console.log(`Total memory used: ${Math.round(memory.rss / 1024 / 1024)} MB`)
        main()
    }, 1000);
}

main().catch(console.error)

Nikaple avatar May 16 '23 08:05 Nikaple