No memory leak on repeated connect/disconnect calls.
Actual behaviour
Library is leaking memory when you try to repeatedly connect/disconnect in attempt to reconnect to remote host after some form of network interruption leading to a disconnection. Not sure if there's any better approach to reconnecting.
Steps to reproduce the behaviour
Consider given code:
var pub = new PublisherSocket();
var port = pub.BindRandomPort("tcp://127.0.0.1");
for (int i = 0; i < 1000; i++)
{
var sub = new SubscriberSocket();
sub.Connect("tcp://127.0.0.1:" + port);
sub.Subscribe("A");
sub.Disconnect("tcp://127.0.0.1:" + port);
sub.Dispose();
Thread.Sleep(50);
}
It will repeatedly connect and disconnect to the single pub socket. Unfortunatelly Close/Disconnect/Dispose methods won't fully cleanup used resources as visible on Visual Studio profiler:
There is ever increasing number of Pipe instances.
I've been trying to pinpoint the issue in cloned repository but I'm unable to find it. What I've noticed is that when counting created Pipe instances only other 2nd pair will be garbage collected eg: (not entirely sure if it's a good indicator)
private Pipe(
ZObject parent, YPipe<Msg> inboundPipe, YPipe<Msg> outboundPipe,
int inHighWatermark, int outHighWatermark, int predefinedLowWatermark)
: base(parent)
{
...
_id = Interlocked.Increment(ref IdCounter);
Console.WriteLine($"Created: {_id}");
}
~Pipe()
{
Console.WriteLine($"Finalized: {_id}");
}
Environment
Expected behaviour
No memory leak on repeated connect/disconnect calls.
Actual behaviour
Library is leaking memory when you try to repeatedly connect/disconnect in attempt to reconnect to remote host after some form of network interruption leading to a disconnection. Not sure if there's any better approach to reconnecting.
Steps to reproduce the behaviour
Consider given code:
It will repeatedly connect and disconnect to the single![image](https://user-images.githubusercontent.com/6102530/196442069-87bab8b6-09a6-4517-a96a-aa2549c64a29.png)
pub
socket. UnfortunatellyClose
/Disconnect
/Dispose
methods won't fully cleanup used resources as visible on Visual Studio profiler:There is ever increasing number of![image](https://user-images.githubusercontent.com/6102530/196442250-6b729f29-a981-408a-972a-7669a5cc8178.png)
Pipe
instances.I've been trying to pinpoint the issue in cloned repository but I'm unable to find it. What I've noticed is that when counting created
Pipe
instances only other 2nd pair will be garbage collected eg: (not entirely sure if it's a good indicator)This suggests that the pipes of
pub
sockets are left around.The memory has been leaking over the span of several days/weeks including the case where the
pub
socket was on remote system.Thanks for help!