Skip to content

AsyncBase implementations not freeing allocated nng_ctx #110

Description

@biocommando

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions