From 3a706d4b2d50431047da489585c5bd67ad846900 Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Thu, 4 Feb 2021 04:16:33 -0800 Subject: [PATCH] fix #750: enable gc for watch mode --- CHANGELOG.md | 8 ++++++++ cmd/esbuild/main.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40d38fb478c..62edfcfd706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## Unreleased +* Fix memory leak with watch mode when using the CLI ([#750](https://github.com/evanw/esbuild/issues/750)) + + This release fixes a memory leak when using `--watch` from the CLI (command-line interface). When esbuild was in this state, every incremental build resulted in more memory being consumed. This problem did not affect users of the JS API or Go API, only users of the CLI API. + + The problem was that the GC (garbage collector) was disabled. Oops. This is done by default for speed when you use esbuild via the CLI, which makes sense for most CLI use cases because the process is usually short-lived and doesn't need to waste time cleaning up memory. But it does not make sense for flags that cause esbuild to be a long-running process. + + Previously the only exception to this rule was the `--serve` flag. When I added watch mode, I forgot to enable GC for the `--watch` flag too. With this release, the GC is enabled for both the `--serve` and the `--watch` flags so esbuild should no longer leak memory in watch mode. + * Special-case certain syntax with `--format=esm` ([#749](https://github.com/evanw/esbuild/issues/749)) You can now no longer use the following syntax features with the `esm` output format: diff --git a/cmd/esbuild/main.go b/cmd/esbuild/main.go index 13e44b1f0d8..da7373992b9 100644 --- a/cmd/esbuild/main.go +++ b/cmd/esbuild/main.go @@ -228,10 +228,10 @@ func main() { exitCode = cli.Run(osArgs) } } else { - // Don't disable the GC if this is a long-running server process + // Don't disable the GC if this is a long-running process isServe := false for _, arg := range osArgs { - if arg == "--serve" || strings.HasPrefix(arg, "--serve=") { + if arg == "--serve" || arg == "--watch" || strings.HasPrefix(arg, "--serve=") { isServe = true break }