You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During watch mode, each new child compiler creates a copy of source strings, which are never removed from memory.
I think I've narrowed this down to this commit aa64b82 where HtmlWebpackPlugin started using a unique ID for each child compiler instead of the template path. This cache in MemoryCachePlugin uses the unique ID when storing an entry, so the cache entries grow with each compilation.
I don't see any mention of the change in the changelog or PR description (😄) so I'm not sure why the change was made, but id doesn't seem to be used anywhere else in HtmlWebpackPlugin. Let me know if there's an explanation I'm missing somewhere!
Potential fix 🛠️
The memory leak goes away when aa64b82 is reverted to use template, and unit tests still pass. Is it possible to revert this change, or if it's solving a problem, to implement it in a different way? I'm happy to help.
Screenshots
Duplicated strings in memory
The size of the leak is small in this example, but the reproduction repo below shows an example of a much larger leak.
MemoryCachePlugin cache
Note the HtmlWebpackPlugin_0-15 - this is the 15th iteration i.e. 15th child compiler.
Expected behaviour ☀️
Source strings are cleaned up (or able to be garbage collected) between recompilations in watch mode
Current behaviour 💣
During watch mode, each new child compiler creates a copy of source strings, which are never removed from memory.
I think I've narrowed this down to this commit aa64b82 where HtmlWebpackPlugin started using a unique ID for each child compiler instead of the template path. This cache in MemoryCachePlugin uses the unique ID when storing an entry, so the cache entries grow with each compilation.
I don't see any mention of the change in the changelog or PR description (😄) so I'm not sure why the change was made, but
id
doesn't seem to be used anywhere else inHtmlWebpackPlugin
. Let me know if there's an explanation I'm missing somewhere!Potential fix 🛠️
The memory leak goes away when aa64b82 is reverted to use
template
, and unit tests still pass. Is it possible to revert this change, or if it's solving a problem, to implement it in a different way? I'm happy to help.Screenshots
Duplicated strings in memory
The size of the leak is small in this example, but the reproduction repo below shows an example of a much larger leak.
MemoryCachePlugin cache
Note the
HtmlWebpackPlugin_0-15
- this is the 15th iteration i.e. 15th child compiler.Expected behaviour ☀️
Source strings are cleaned up (or able to be garbage collected) between recompilations in watch mode
Reproduction Example 👾
The main branch of this repo includes a custom loader that makes the leak obvious: https://github.com/helloitsjoe/webpack-cache-memory-leak
But the leak is also visible on this simplified branch with vanilla use of HtmlWebpackPlugin: https://github.com/helloitsjoe/webpack-cache-memory-leak/tree/simplified
Environment 🖥
The text was updated successfully, but these errors were encountered: