Removing IDisposable from NetworkConnection (#2345)

* clientOwnedObjects is a hash set which doesn't need to be disposed
* DestroyOwnedObjects already clears list which is called by networkmanager when connection disconnects

Co-authored-by: vis2k <info@noobtuts.com>
This commit is contained in:
James Frowen 2020-10-22 08:50:37 +01:00 committed by GitHub
parent 46d8077780
commit 06ae90878d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 33 deletions

View File

@ -215,14 +215,6 @@ public static void Disconnect()
if (connection != null)
{
connection.Disconnect();
// connection.Disconnect calls Transport.ClientDisconnect.
// if transport calls Mirror's OnDisconnected event immediately
// before returning, then we end up in a circular call:
// https://github.com/vis2k/Mirror/issues/2353
// in which case connection becomes null after returning here.
// in other words, the following Dispose call needs to use '.?'
// to avoid NullReferenceExceptions.
connection?.Dispose();
connection = null;
RemoveTransportHandlers();
}

View File

@ -14,7 +14,7 @@ namespace Mirror
/// <para>NetworkConnection objects also act as observers for networked objects. When a connection is an observer of a networked object with a NetworkIdentity, then the object will be visible to corresponding client for the connection, and incremental state changes will be sent to the client.</para>
/// <para>There are many virtual functions on NetworkConnection that allow its behaviour to be customized. NetworkClient and NetworkServer can both be made to instantiate custom classes derived from NetworkConnection by setting their networkConnectionClass member variable.</para>
/// </remarks>
public abstract class NetworkConnection : IDisposable
public abstract class NetworkConnection
{
public const int LocalConnectionId = 0;
static readonly ILogger logger = LogFactory.GetLogger<NetworkConnection>();
@ -107,28 +107,6 @@ internal NetworkConnection(int networkConnectionId) : this()
connectionId = networkConnectionId;
}
~NetworkConnection()
{
Dispose(false);
}
/// <summary>
/// Disposes of this connection, releasing channel buffers that it holds.
/// </summary>
public void Dispose()
{
Dispose(true);
// Take yourself off the Finalization queue
// to prevent finalization code for this object
// from executing a second time.
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
clientOwnedObjects.Clear();
}
/// <summary>
/// Disconnects this connection.
/// </summary>

View File

@ -236,7 +236,6 @@ internal static void RemoveLocalConnection()
if (localConnection != null)
{
localConnection.Disconnect();
localConnection.Dispose();
localConnection = null;
}
RemoveConnection(0);
@ -473,7 +472,6 @@ public static void DisconnectAllConnections()
// call OnDisconnected unless local player in host mode
if (conn.connectionId != NetworkConnection.LocalConnectionId)
OnDisconnected(conn);
conn.Dispose();
}
connections.Clear();
}