Răsfoiți Sursa

Remove unnecessary finalizers (#1209)

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.

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
Rob Hague 1 an în urmă
părinte
comite
a157dd3b88

+ 0 - 8
src/Renci.SshNet/BaseClient.cs

@@ -461,14 +461,6 @@ namespace Renci.SshNet
 #endif // NET7_0_OR_GREATER
         }
 
-        /// <summary>
-        /// Finalizes an instance of the <see cref="BaseClient"/> class.
-        /// </summary>
-        ~BaseClient()
-        {
-            Dispose(disposing: false);
-        }
-
         /// <summary>
         /// Stops the keep-alive timer, and waits until all timer callbacks have been
         /// executed.

+ 0 - 8
src/Renci.SshNet/Channels/Channel.cs

@@ -868,13 +868,5 @@ namespace Renci.SshNet.Channels
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="Channel"/> class.
-        /// </summary>
-        ~Channel()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 9
src/Renci.SshNet/Compression/Compressor.cs

@@ -175,14 +175,5 @@ namespace Renci.SshNet.Compression
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Releases unmanaged resources and performs other cleanup operations before the <see cref="Compressor"/> is reclaimed
-        /// by garbage collection.
-        /// </summary>
-        ~Compressor()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/ForwardedPortRemote.cs

@@ -379,13 +379,5 @@ namespace Renci.SshNet
 
             _isDisposed = true;
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="ForwardedPortRemote"/> class.
-        /// </summary>
-        ~ForwardedPortRemote()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs

@@ -183,13 +183,5 @@ namespace Renci.SshNet
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="KeyboardInteractiveAuthenticationMethod"/> class.
-        /// </summary>
-        ~KeyboardInteractiveAuthenticationMethod()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs

@@ -174,13 +174,5 @@ namespace Renci.SshNet
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
-        /// </summary>
-        ~KeyboardInteractiveConnectionInfo()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/NoneAuthenticationMethod.cs

@@ -121,13 +121,5 @@ namespace Renci.SshNet
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="NoneAuthenticationMethod"/> class.
-        /// </summary>
-        ~NoneAuthenticationMethod()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/PasswordAuthenticationMethod.cs

@@ -201,13 +201,5 @@ namespace Renci.SshNet
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="PasswordAuthenticationMethod"/> class.
-        /// </summary>
-        ~PasswordAuthenticationMethod()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/PasswordConnectionInfo.cs

@@ -291,13 +291,5 @@ namespace Renci.SshNet
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="PasswordConnectionInfo"/> class.
-        /// </summary>
-        ~PasswordConnectionInfo()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs

@@ -191,14 +191,6 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Finalizes an instance of the <see cref="PrivateKeyAuthenticationMethod"/> class.
-        /// </summary>
-        ~PrivateKeyAuthenticationMethod()
-        {
-            Dispose(disposing: false);
-        }
-
         private sealed class SignatureData : SshData
         {
             private readonly RequestMessagePublicKey _message;

+ 0 - 8
src/Renci.SshNet/PrivateKeyConnectionInfo.cs

@@ -170,13 +170,5 @@ namespace Renci.SshNet
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="PrivateKeyConnectionInfo"/> class.
-        /// </summary>
-        ~PrivateKeyConnectionInfo()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/PrivateKeyFile.cs

@@ -669,14 +669,6 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Finalizes an instance of the <see cref="PrivateKeyFile"/> class.
-        /// </summary>
-        ~PrivateKeyFile()
-        {
-            Dispose(disposing: false);
-        }
-
         private sealed class SshDataReader : SshData
         {
             public SshDataReader(byte[] data)

+ 0 - 8
src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs

@@ -83,13 +83,5 @@ namespace Renci.SshNet.Security.Cryptography
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="ED25519DigitalSignature"/> class.
-        /// </summary>
-        ~ED25519DigitalSignature()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/Security/Cryptography/ED25519Key.cs

@@ -131,13 +131,5 @@ namespace Renci.SshNet.Security
                 _isDisposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="ED25519Key"/> class.
-        /// </summary>
-        ~ED25519Key()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 9
src/Renci.SshNet/Security/KeyExchange.cs

@@ -564,15 +564,6 @@ namespace Renci.SshNet.Security
         {
         }
 
-        /// <summary>
-        /// Releases unmanaged resources and performs other cleanup operations before the
-        /// <see cref="KeyExchange"/> is reclaimed by garbage collection.
-        /// </summary>
-        ~KeyExchange()
-        {
-            Dispose(disposing: false);
-        }
-
         #endregion
     }
 }

+ 0 - 8
src/Renci.SshNet/Session.cs

@@ -2253,14 +2253,6 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Finalizes an instance of the <see cref="Session"/> class.
-        /// </summary>
-        ~Session()
-        {
-            Dispose(disposing: false);
-        }
-
         /// <summary>
         /// Gets the connection info.
         /// </summary>

+ 0 - 5
src/Renci.SshNet/Sftp/SftpFileReader.cs

@@ -219,11 +219,6 @@ namespace Renci.SshNet.Sftp
             return read;
         }
 
-        ~SftpFileReader()
-        {
-            Dispose(disposing: false);
-        }
-
         public void Dispose()
         {
             Dispose(disposing: true);

+ 0 - 8
src/Renci.SshNet/Sftp/SftpFileStream.cs

@@ -439,14 +439,6 @@ namespace Renci.SshNet.Sftp
             return new SftpFileStream(session, path, access, bufferSize, handle, position);
         }
 
-        /// <summary>
-        /// Finalizes an instance of the <see cref="SftpFileStream"/> class.
-        /// </summary>
-        ~SftpFileStream()
-        {
-            Dispose(disposing: false);
-        }
-
         /// <summary>
         /// Clears all buffers for this stream and causes any buffered data to be written to the file.
         /// </summary>

+ 0 - 8
src/Renci.SshNet/Shell.cs

@@ -350,13 +350,5 @@ namespace Renci.SshNet
                 _disposed = true;
             }
         }
-
-        /// <summary>
-        /// Finalizes an instance of the <see cref="Shell"/> class.
-        /// </summary>
-        ~Shell()
-        {
-            Dispose(disposing: false);
-        }
     }
 }

+ 0 - 8
src/Renci.SshNet/SubsystemSession.cs

@@ -537,14 +537,6 @@ namespace Renci.SshNet
             }
         }
 
-        /// <summary>
-        /// Finalizes an instance of the <see cref="SubsystemSession" /> class.
-        /// </summary>
-        ~SubsystemSession()
-        {
-            Dispose(disposing: false);
-        }
-
         private void EnsureNotDisposed()
         {
 #if NET7_0_OR_GREATER