ligershark / WebOptimizer

A bundler and minifier for ASP.NET Core
Apache License 2.0
771 stars 114 forks source link

Memory leak #170

Closed puhnastik closed 3 years ago

puhnastik commented 3 years ago

We are observing memory leak in WebOptimizer code. Memory usage graphs with WebOptimizer in place starting from 04/17 show significant increase in memory that doesn't get released and application eventually runs out of memory. image

I can reproduce the same issue on WebOptimizer demo sample

Steps to reproduce:

  1. Run demo sample (any environment)
  2. Open demo application in a browser and reload the page several times with browser cache disabled to ensure that static resources are requested on each page reload.
  3. Create a memory dump for analysis or snapshot of memory profiler. I used dotMemory with configuration: image
  4. Analyze memory snapshot

The snapshot from dotMemory profiler shows increasing number of WebOptimizerConfig objects that don't get garbage collected. There is one new WebOptimizerConfig object get's created for each call to static content file. image

The issue seems to be in the ConfigurationReloadToken that doesn't get disposed (link to the code)[https://github.com/ligershark/WebOptimizer/blob/master/src/WebOptimizer.Core/WebOptimizerConfig.cs#L24] image image

Attached dotMemory workspace for the demo sample WebOptimizer.Core.Sample.dmw.zip

madskristensen commented 3 years ago

Thank you so much for the best bug report I've ever received in my many years of doing OSS on GitHub!!!!

mshiveral commented 3 years ago

Thanks for picking this up and turning it around so quickly @madskristensen! We plan on picking up the fix and verifying it in our DEV environment tomorrow.

Thanks!

mshiveral commented 3 years ago

Just confirming that the fix looks good in both our DEV and PERF environments @madskristensen. Sorry for late reply (I was out for few days) and thanks for quick fix here!

madskristensen commented 3 years ago

@mshiveral awesome, thanks for the follow-up!!!