Is it a memory leak?

I have a class shown below. The server instance contains a reference to the listener instance. The listener refers to the server instance through the event delegate. Will this stop the GC from building the server instance? If so, how to break this loop? Should I implement IDisposable or override the Finalize method or do something else?

public class Server
    {        
        public Listener Listener { get; private set; }        

        public Server(Listener listener)
        {
            Listener = listener;
            Listener.ClientChannelConnected += new EventHandler<ClientChannelConnectedArgs>(listener_ClientChannelConnected);
        }        

        void listener_ClientChannelConnected(object sender, ClientChannelConnectedArgs e)
        {
            ...
        }
}
+3
source share
3 answers

No. The .NET garbage collector is smart enough to allow circular references.

+1
source

, , .net - - . , , .

, , .

+1

Read this article about memory leaks . Sometimes you have to use - =.

0
source

Source: https://habr.com/ru/post/1757281/


All Articles