OmniSharp / csharp-language-server-protocol

Language Server Protocol in C#
MIT License
499 stars 100 forks source link

Suspected Memory Leak in Language Client #1037

Open antpensi opened 9 months ago

antpensi commented 9 months ago

Hello

I am investigating a suspected memory leak in the Omnisharp Language Client. When configuring the client to handle a periodic notification from an external Language Server, I consistently observe memory usage growing unbounded.

The memory profiler within VS indicates this is coming from many Newtonsoft.Json.Linq.* objects related to the OmniSharp.Extensions.JsonRpc.Server.Notification class.

These objects appear to grow even when constructing a "no-op" notification handler, which leads me to believe it may be internal to this library.

Here is how I am constructing my Language Client -

Process process = new Process(...configured for myLangServer.exe...);

LanguageClientOptions options = new LanguageClientOptions();
options.WithInput(process.StandardOutput.BaseStream)
       .WithOutput(process.StandardInput.BaseStream)
       .OnNotification("foo/bar", (MyNotification notification) =>
       {
        Debug.Print($"Notification received.");
       });

var languageClient = OmniSharp.Extensions.LanguageServer.Client.LanguageClient.Create(options);
await languageClient.Initialize(CancellationToken.None);

I am using version 0.19.7 of the Omnisharp.Extensions.LanguageClient NuGet package. Attaching an image detailing an example of one of these Newtonsoft objects.

devenv_PaNuYVndH7

antpensi commented 9 months ago

image