Skip to content
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

AsyncBase implementations not freeing allocated nng_ctx #110

Open
biocommando opened this issue Apr 20, 2023 · 0 comments
Open

AsyncBase implementations not freeing allocated nng_ctx #110

biocommando opened this issue Apr 20, 2023 · 0 comments

Comments

@biocommando
Copy link

biocommando commented Apr 20, 2023

Some classes that extend AsyncBase contain a member field Ctx. The field implements INngCtx which does not implement IDisposable but the actual implementation class NngCtx does. This leads to the implementation never disposing of the Ctx field and leaking memory when the async context is disposed of.

You can reproduce it by running this code. If you run it in Visual Studio using heap profiling, you can see that every 100 ms there will be an allocation originating from nng.dll:

using nng;
var factory = nng.NngLoadContext.Init(new(Path.GetDirectoryName(typeof(Program).Assembly.Location)));
using var repSocket = factory.ReplierOpen().ThenListen("inproc://1").Unwrap();
while (true)
{
  using var repAsyncCtx = repSocket.CreateAsyncContext(factory).Unwrap();
  await Task.Delay(100);
}

image

Adding this line to the while loop makes the allocations dissappear (i.e. memory is freed):

((IDisposable)repAsyncCtx.Ctx).Dispose();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant