From deb9a9179c2decb2149abbd3ee14550aa2759caa Mon Sep 17 00:00:00 2001 From: Robert Hague Date: Sat, 14 Oct 2023 17:01:11 +0200 Subject: [PATCH] Remove unnecessary finalizers All of the finalizers in the library are no-ops, but their existence means that when Dispose (and thus GC.SuppressFinalize) is not called, the objects' lifetimes are extended unnecessarily while they are waiting to be finalized. --- src/Renci.SshNet/BaseClient.cs | 8 -------- src/Renci.SshNet/Channels/Channel.cs | 8 -------- src/Renci.SshNet/Compression/Compressor.cs | 9 --------- src/Renci.SshNet/ForwardedPortDynamic.cs | 8 -------- src/Renci.SshNet/ForwardedPortLocal.cs | 8 -------- src/Renci.SshNet/ForwardedPortRemote.cs | 8 -------- .../KeyboardInteractiveAuthenticationMethod.cs | 8 -------- src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs | 8 -------- src/Renci.SshNet/NoneAuthenticationMethod.cs | 8 -------- src/Renci.SshNet/PasswordAuthenticationMethod.cs | 8 -------- src/Renci.SshNet/PasswordConnectionInfo.cs | 8 -------- src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs | 8 -------- src/Renci.SshNet/PrivateKeyConnectionInfo.cs | 8 -------- src/Renci.SshNet/PrivateKeyFile.cs | 8 -------- .../Security/Cryptography/DsaDigitalSignature.cs | 8 -------- src/Renci.SshNet/Security/Cryptography/DsaKey.cs | 8 -------- .../Security/Cryptography/ED25519DigitalSignature.cs | 8 -------- src/Renci.SshNet/Security/Cryptography/ED25519Key.cs | 8 -------- .../Security/Cryptography/EcdsaDigitalSignature.cs | 8 -------- src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs | 8 -------- .../Security/Cryptography/RsaDigitalSignature.cs | 9 --------- src/Renci.SshNet/Security/Cryptography/RsaKey.cs | 9 --------- src/Renci.SshNet/Security/KeyExchange.cs | 9 --------- src/Renci.SshNet/Session.cs | 8 -------- src/Renci.SshNet/Sftp/SftpFileReader.cs | 5 ----- src/Renci.SshNet/Sftp/SftpFileStream.cs | 8 -------- src/Renci.SshNet/Shell.cs | 8 -------- src/Renci.SshNet/SshCommand.cs | 10 ---------- src/Renci.SshNet/SubsystemSession.cs | 8 -------- 29 files changed, 235 deletions(-) diff --git a/src/Renci.SshNet/BaseClient.cs b/src/Renci.SshNet/BaseClient.cs index a879c02f8..2d8d91594 100644 --- a/src/Renci.SshNet/BaseClient.cs +++ b/src/Renci.SshNet/BaseClient.cs @@ -439,14 +439,6 @@ protected void CheckDisposed() } } - /// - /// Finalizes an instance of the class. - /// - ~BaseClient() - { - Dispose(disposing: false); - } - /// /// Stops the keep-alive timer, and waits until all timer callbacks have been /// executed. diff --git a/src/Renci.SshNet/Channels/Channel.cs b/src/Renci.SshNet/Channels/Channel.cs index d3ec7ca6c..dc9ecefe2 100644 --- a/src/Renci.SshNet/Channels/Channel.cs +++ b/src/Renci.SshNet/Channels/Channel.cs @@ -863,13 +863,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~Channel() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/Compression/Compressor.cs b/src/Renci.SshNet/Compression/Compressor.cs index df887aa1c..8de4ac0df 100644 --- a/src/Renci.SshNet/Compression/Compressor.cs +++ b/src/Renci.SshNet/Compression/Compressor.cs @@ -171,14 +171,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Releases unmanaged resources and performs other cleanup operations before the is reclaimed - /// by garbage collection. - /// - ~Compressor() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/ForwardedPortDynamic.cs b/src/Renci.SshNet/ForwardedPortDynamic.cs index 1331557a8..14d8ca3ee 100644 --- a/src/Renci.SshNet/ForwardedPortDynamic.cs +++ b/src/Renci.SshNet/ForwardedPortDynamic.cs @@ -158,13 +158,5 @@ protected override void Dispose(bool disposing) InternalDispose(disposing); _isDisposed = true; } - - /// - /// Finalizes an instance of the class. - /// - ~ForwardedPortDynamic() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/ForwardedPortLocal.cs b/src/Renci.SshNet/ForwardedPortLocal.cs index 8dabb09fb..bc3ae38c4 100644 --- a/src/Renci.SshNet/ForwardedPortLocal.cs +++ b/src/Renci.SshNet/ForwardedPortLocal.cs @@ -205,13 +205,5 @@ protected override void Dispose(bool disposing) InternalDispose(disposing); _isDisposed = true; } - - /// - /// Finalizes an instance of the class. - /// - ~ForwardedPortLocal() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/ForwardedPortRemote.cs b/src/Renci.SshNet/ForwardedPortRemote.cs index ce465e12e..081519ed8 100644 --- a/src/Renci.SshNet/ForwardedPortRemote.cs +++ b/src/Renci.SshNet/ForwardedPortRemote.cs @@ -384,13 +384,5 @@ protected override void Dispose(bool disposing) _isDisposed = true; } - - /// - /// Finalizes an instance of the class. - /// - ~ForwardedPortRemote() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs b/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs index 1e0a743ce..861afb688 100644 --- a/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs +++ b/src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs @@ -173,13 +173,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~KeyboardInteractiveAuthenticationMethod() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs b/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs index af2667842..c9b4d38ee 100644 --- a/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs +++ b/src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs @@ -178,13 +178,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~KeyboardInteractiveConnectionInfo() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/NoneAuthenticationMethod.cs b/src/Renci.SshNet/NoneAuthenticationMethod.cs index 99d025249..58d5dede1 100644 --- a/src/Renci.SshNet/NoneAuthenticationMethod.cs +++ b/src/Renci.SshNet/NoneAuthenticationMethod.cs @@ -121,13 +121,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~NoneAuthenticationMethod() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/PasswordAuthenticationMethod.cs b/src/Renci.SshNet/PasswordAuthenticationMethod.cs index bebfd3c47..68cc25cd9 100644 --- a/src/Renci.SshNet/PasswordAuthenticationMethod.cs +++ b/src/Renci.SshNet/PasswordAuthenticationMethod.cs @@ -201,13 +201,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~PasswordAuthenticationMethod() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/PasswordConnectionInfo.cs b/src/Renci.SshNet/PasswordConnectionInfo.cs index 28317411d..3451a2df1 100644 --- a/src/Renci.SshNet/PasswordConnectionInfo.cs +++ b/src/Renci.SshNet/PasswordConnectionInfo.cs @@ -299,13 +299,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~PasswordConnectionInfo() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs b/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs index 224f8d295..e8cfa06a1 100644 --- a/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs +++ b/src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs @@ -191,14 +191,6 @@ protected virtual void Dispose(bool disposing) } } - /// - /// Finalizes an instance of the class. - /// - ~PrivateKeyAuthenticationMethod() - { - Dispose(disposing: false); - } - private sealed class SignatureData : SshData { private readonly RequestMessagePublicKey _message; diff --git a/src/Renci.SshNet/PrivateKeyConnectionInfo.cs b/src/Renci.SshNet/PrivateKeyConnectionInfo.cs index 29b48ffaa..aa0db6cd4 100644 --- a/src/Renci.SshNet/PrivateKeyConnectionInfo.cs +++ b/src/Renci.SshNet/PrivateKeyConnectionInfo.cs @@ -177,13 +177,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~PrivateKeyConnectionInfo() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/PrivateKeyFile.cs b/src/Renci.SshNet/PrivateKeyFile.cs index 6dc8d4274..cc147d353 100644 --- a/src/Renci.SshNet/PrivateKeyFile.cs +++ b/src/Renci.SshNet/PrivateKeyFile.cs @@ -635,14 +635,6 @@ protected virtual void Dispose(bool disposing) } } - /// - /// Finalizes an instance of the class. - /// - ~PrivateKeyFile() - { - Dispose(disposing: false); - } - private sealed class SshDataReader : SshData { public SshDataReader(byte[] data) diff --git a/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs index 467a5e0a7..555452c62 100644 --- a/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs +++ b/src/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs @@ -193,13 +193,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~DsaDigitalSignature() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/Security/Cryptography/DsaKey.cs b/src/Renci.SshNet/Security/Cryptography/DsaKey.cs index 1c239aebe..a95ad20c7 100644 --- a/src/Renci.SshNet/Security/Cryptography/DsaKey.cs +++ b/src/Renci.SshNet/Security/Cryptography/DsaKey.cs @@ -182,13 +182,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~DsaKey() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs index c777f4d48..50b55b389 100644 --- a/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs +++ b/src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs @@ -79,13 +79,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~ED25519DigitalSignature() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs b/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs index 84dc61178..9e720fad4 100644 --- a/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs +++ b/src/Renci.SshNet/Security/Cryptography/ED25519Key.cs @@ -147,13 +147,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~ED25519Key() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs index 93fc6ba4a..47e740762 100644 --- a/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs +++ b/src/Renci.SshNet/Security/Cryptography/EcdsaDigitalSignature.cs @@ -98,14 +98,6 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~EcdsaDigitalSignature() - { - Dispose(disposing: false); - } } internal sealed class SshDataSignature : SshData diff --git a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs index f6bd50bd0..96eba9005 100644 --- a/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs +++ b/src/Renci.SshNet/Security/Cryptography/EcdsaKey.cs @@ -497,13 +497,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~EcdsaKey() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/Security/Cryptography/RsaDigitalSignature.cs b/src/Renci.SshNet/Security/Cryptography/RsaDigitalSignature.cs index 790a0da64..28fbbbf74 100644 --- a/src/Renci.SshNet/Security/Cryptography/RsaDigitalSignature.cs +++ b/src/Renci.SshNet/Security/Cryptography/RsaDigitalSignature.cs @@ -81,15 +81,6 @@ protected virtual void Dispose(bool disposing) } } - /// - /// Releases unmanaged resources and performs other cleanup operations before the - /// is reclaimed by garbage collection. - /// - ~RsaDigitalSignature() - { - Dispose(disposing: false); - } - #endregion } } diff --git a/src/Renci.SshNet/Security/Cryptography/RsaKey.cs b/src/Renci.SshNet/Security/Cryptography/RsaKey.cs index 7b088ea6e..65e76ad3a 100644 --- a/src/Renci.SshNet/Security/Cryptography/RsaKey.cs +++ b/src/Renci.SshNet/Security/Cryptography/RsaKey.cs @@ -275,14 +275,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Releases unmanaged resources and performs other cleanup operations before the - /// is reclaimed by garbage collection. - /// - ~RsaKey() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/Security/KeyExchange.cs b/src/Renci.SshNet/Security/KeyExchange.cs index 96a912b66..ce6bc3d80 100644 --- a/src/Renci.SshNet/Security/KeyExchange.cs +++ b/src/Renci.SshNet/Security/KeyExchange.cs @@ -518,15 +518,6 @@ protected virtual void Dispose(bool disposing) { } - /// - /// Releases unmanaged resources and performs other cleanup operations before the - /// is reclaimed by garbage collection. - /// - ~KeyExchange() - { - Dispose(disposing: false); - } - #endregion } } diff --git a/src/Renci.SshNet/Session.cs b/src/Renci.SshNet/Session.cs index 257cf8c2c..8477ec464 100644 --- a/src/Renci.SshNet/Session.cs +++ b/src/Renci.SshNet/Session.cs @@ -2042,14 +2042,6 @@ protected virtual void Dispose(bool disposing) } } - /// - /// Finalizes an instance of the class. - /// - ~Session() - { - Dispose(disposing: false); - } - /// /// Gets the connection info. /// diff --git a/src/Renci.SshNet/Sftp/SftpFileReader.cs b/src/Renci.SshNet/Sftp/SftpFileReader.cs index c28dd8ac5..617112a5c 100644 --- a/src/Renci.SshNet/Sftp/SftpFileReader.cs +++ b/src/Renci.SshNet/Sftp/SftpFileReader.cs @@ -213,11 +213,6 @@ public byte[] Read() return read; } - ~SftpFileReader() - { - Dispose(disposing: false); - } - public void Dispose() { Dispose(disposing: true); diff --git a/src/Renci.SshNet/Sftp/SftpFileStream.cs b/src/Renci.SshNet/Sftp/SftpFileStream.cs index a17d5b8ee..7a0ae4f31 100644 --- a/src/Renci.SshNet/Sftp/SftpFileStream.cs +++ b/src/Renci.SshNet/Sftp/SftpFileStream.cs @@ -413,14 +413,6 @@ internal static async Task OpenAsync(ISftpSession session, strin return new SftpFileStream(session, path, access, bufferSize, handle, position); } - /// - /// Finalizes an instance of the class. - /// - ~SftpFileStream() - { - Dispose(disposing: false); - } - /// /// Clears all buffers for this stream and causes any buffered data to be written to the file. /// diff --git a/src/Renci.SshNet/Shell.cs b/src/Renci.SshNet/Shell.cs index 0990ae812..9521b0001 100644 --- a/src/Renci.SshNet/Shell.cs +++ b/src/Renci.SshNet/Shell.cs @@ -295,13 +295,5 @@ protected virtual void Dispose(bool disposing) _disposed = true; } } - - /// - /// Finalizes an instance of the class. - /// - ~Shell() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/SshCommand.cs b/src/Renci.SshNet/SshCommand.cs index a4b861cda..4247ccaae 100644 --- a/src/Renci.SshNet/SshCommand.cs +++ b/src/Renci.SshNet/SshCommand.cs @@ -588,15 +588,5 @@ protected virtual void Dispose(bool disposing) _isDisposed = true; } } - - /// - /// Finalizes an instance of the class. - /// Releases unmanaged resources and performs other cleanup operations before the - /// is reclaimed by garbage collection. - /// - ~SshCommand() - { - Dispose(disposing: false); - } } } diff --git a/src/Renci.SshNet/SubsystemSession.cs b/src/Renci.SshNet/SubsystemSession.cs index 86a081bbf..bbb388149 100644 --- a/src/Renci.SshNet/SubsystemSession.cs +++ b/src/Renci.SshNet/SubsystemSession.cs @@ -537,14 +537,6 @@ protected virtual void Dispose(bool disposing) } } - /// - /// Finalizes an instance of the class. - /// - ~SubsystemSession() - { - Dispose(disposing: false); - } - private void EnsureNotDisposed() { if (_isDisposed)