-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak after configuration disposal from PhysicalFileProvider #86146
Comments
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionWhen application creates many short-living configuration roots, which use files it results in memory leaks around I've checked code and see that while Reproduction Stepsinternal class Program
{
static void Main()
{
const int iterations = int.MaxValue;
for (var i = 0; i < iterations; i++)
{
Test();
}
}
static void Test()
{
var config = new ConfigurationBuilder().AddXmlFile("settings.xml", false, true).Build();
(config as IDisposable)?.Dispose();
}
} Expected behaviorNo memory leaks Actual behaviorMemory leaks We need to support two runtimes currently, so results are for .NET7 and NET48 .NET 7 runtime after ~78k iterations In NETFX 4.8 situation is even worse (expected, as it doesn't have all improvements to file watcher related code) Regression?Nope Known Workaroundspassing external using var fileProvider = new PhysicalFileProvider(AppContext.BaseDirectory);
using var config = new ConfigurationBuilder().AddXmlFile(fileProvider, "settings.xml", false, true).Build() as IDisposable; ConfigurationNo response Other informationNo response
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem Issue DetailsDescriptionWhen application creates many short-living configuration roots, which use files it results in memory leaks around I've checked code and see that while Reproduction Stepsinternal class Program
{
static void Main()
{
const int iterations = int.MaxValue;
for (var i = 0; i < iterations; i++)
{
Test();
}
}
static void Test()
{
var config = new ConfigurationBuilder().AddXmlFile("settings.xml", false, true).Build();
(config as IDisposable)?.Dispose();
}
} Expected behaviorNo memory leaks Actual behaviorMemory leaks We need to support two runtimes currently, so results are for .NET7 and NET48 .NET 7 runtime after ~78k iterations In NETFX 4.8 situation is even worse (expected, as it doesn't have all improvements to file watcher related code) Regression?Nope Known Workaroundspassing external using var fileProvider = new PhysicalFileProvider(AppContext.BaseDirectory);
using var config = new ConfigurationBuilder().AddXmlFile(fileProvider, "settings.xml", false, true).Build() as IDisposable; ConfigurationNo response Other informationNo response
|
Tagging subscribers to this area: @dotnet/area-extensions-configuration Issue DetailsDescriptionWhen application creates many short-living configuration roots, which use files it results in memory leaks around I've checked code and see that while Reproduction Stepsinternal class Program
{
static void Main()
{
const int iterations = int.MaxValue;
for (var i = 0; i < iterations; i++)
{
Test();
}
}
static void Test()
{
var config = new ConfigurationBuilder().AddXmlFile("settings.xml", false, true).Build();
(config as IDisposable)?.Dispose();
}
} Expected behaviorNo memory leaks Actual behaviorMemory leaks We need to support two runtimes currently, so results are for .NET7 and NET48 .NET 7 runtime after ~78k iterations In NETFX 4.8 situation is even worse (expected, as it doesn't have all improvements to file watcher related code) Regression?Nope Known Workaroundspassing external using var fileProvider = new PhysicalFileProvider(AppContext.BaseDirectory);
using var config = new ConfigurationBuilder().AddXmlFile(fileProvider, "settings.xml", false, true).Build() as IDisposable; ConfigurationNo response Other informationNo response
|
Hi @MaceWindu Thank you for a bug report with repro case! I was able to repro the bug and send a fix: #86455 I've also created a proposal to help the users avoid getting into the leak: #86456 |
I am reopening the issue (I am also going to unlock the conversation) because my fix introduced a bug and I need to revert it. |
Description
When application creates many short-living configuration roots, which use files it results in memory leaks around
FileSystemWatcher
class (in our case we setup test environment for each test and it leads to memory/performance issues as we have around 100k tests).I've checked code and see that while
ConfigurationRoot.Dispose
disposesIConfigurationProvider
instances,FileConfigurationProvider.Dispose
disposes only_changeTokenRegistration
and file (folder actually) watch infrastructure inFileConfigurationSource
is never disposed.Reproduction Steps
Expected behavior
No memory leaks
Actual behavior
Memory leaks
We need to support two runtimes currently, so results are for .NET7 and NET48
.NET 7 runtime after ~78k iterations


where byte[] instances are
In NETFX 4.8 situation is even worse (expected, as it doesn't have all improvements to file watcher related code)

Regression?
Nope
Known Workarounds
passing external
PhysicalFileProvider
instance and dispose it explicitly fixes leak completely:Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: