RoslynCodeDomProvider icon indicating copy to clipboard operation
RoslynCodeDomProvider copied to clipboard

Found resource/memory leak from never disposing of a disposable inside of a linq query.

Open AraHaan opened this issue 2 years ago • 1 comments

The code here: https://github.com/aspnet/RoslynCodeDomProvider/blob/main/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Compiler.cs#L52-L56

Contains a resource/memory leak from not disposing of the disposable inside of the .Select when it gets computed at runtime for each item in it.

The best way to fix this is to use the simplified using syntax by setting <LangVersion>8</LangVersion> or newer inside of the csproj.

For .NET Framework projects I have tested that even the absolute latest language version in the latest compiler binaries (even the preview ones in VS2022 Preview) works, even when the language version of preview is used as well. Just got to be aware of what specific features to avoid however.

AraHaan avatar Nov 17 '23 19:11 AraHaan

I only found this when I started to port the code over myself to my own project to improve it as it seems this repository is not maintained much and I needed some much needed fixes ASAP.

AraHaan avatar Nov 17 '23 20:11 AraHaan