Skip to content

Commit a157dd3

Browse files
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 <[email protected]>
1 parent d06dfa5 commit a157dd3

20 files changed

+0
-159
lines changed

src/Renci.SshNet/BaseClient.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,6 @@ protected void CheckDisposed()
461461
#endif // NET7_0_OR_GREATER
462462
}
463463

464-
/// <summary>
465-
/// Finalizes an instance of the <see cref="BaseClient"/> class.
466-
/// </summary>
467-
~BaseClient()
468-
{
469-
Dispose(disposing: false);
470-
}
471-
472464
/// <summary>
473465
/// Stops the keep-alive timer, and waits until all timer callbacks have been
474466
/// executed.

src/Renci.SshNet/Channels/Channel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -868,13 +868,5 @@ protected virtual void Dispose(bool disposing)
868868
_isDisposed = true;
869869
}
870870
}
871-
872-
/// <summary>
873-
/// Finalizes an instance of the <see cref="Channel"/> class.
874-
/// </summary>
875-
~Channel()
876-
{
877-
Dispose(disposing: false);
878-
}
879871
}
880872
}

src/Renci.SshNet/Compression/Compressor.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,5 @@ protected virtual void Dispose(bool disposing)
175175
_isDisposed = true;
176176
}
177177
}
178-
179-
/// <summary>
180-
/// Releases unmanaged resources and performs other cleanup operations before the <see cref="Compressor"/> is reclaimed
181-
/// by garbage collection.
182-
/// </summary>
183-
~Compressor()
184-
{
185-
Dispose(disposing: false);
186-
}
187178
}
188179
}

src/Renci.SshNet/ForwardedPortRemote.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,13 +379,5 @@ protected override void Dispose(bool disposing)
379379

380380
_isDisposed = true;
381381
}
382-
383-
/// <summary>
384-
/// Finalizes an instance of the <see cref="ForwardedPortRemote"/> class.
385-
/// </summary>
386-
~ForwardedPortRemote()
387-
{
388-
Dispose(disposing: false);
389-
}
390382
}
391383
}

src/Renci.SshNet/KeyboardInteractiveAuthenticationMethod.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,5 @@ protected virtual void Dispose(bool disposing)
183183
_isDisposed = true;
184184
}
185185
}
186-
187-
/// <summary>
188-
/// Finalizes an instance of the <see cref="KeyboardInteractiveAuthenticationMethod"/> class.
189-
/// </summary>
190-
~KeyboardInteractiveAuthenticationMethod()
191-
{
192-
Dispose(disposing: false);
193-
}
194186
}
195187
}

src/Renci.SshNet/KeyboardInteractiveConnectionInfo.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,5 @@ protected virtual void Dispose(bool disposing)
174174
_isDisposed = true;
175175
}
176176
}
177-
178-
/// <summary>
179-
/// Finalizes an instance of the <see cref="KeyboardInteractiveConnectionInfo"/> class.
180-
/// </summary>
181-
~KeyboardInteractiveConnectionInfo()
182-
{
183-
Dispose(disposing: false);
184-
}
185177
}
186178
}

src/Renci.SshNet/NoneAuthenticationMethod.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,5 @@ protected virtual void Dispose(bool disposing)
121121
_isDisposed = true;
122122
}
123123
}
124-
125-
/// <summary>
126-
/// Finalizes an instance of the <see cref="NoneAuthenticationMethod"/> class.
127-
/// </summary>
128-
~NoneAuthenticationMethod()
129-
{
130-
Dispose(disposing: false);
131-
}
132124
}
133125
}

src/Renci.SshNet/PasswordAuthenticationMethod.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,5 @@ protected virtual void Dispose(bool disposing)
201201
_isDisposed = true;
202202
}
203203
}
204-
205-
/// <summary>
206-
/// Finalizes an instance of the <see cref="PasswordAuthenticationMethod"/> class.
207-
/// </summary>
208-
~PasswordAuthenticationMethod()
209-
{
210-
Dispose(disposing: false);
211-
}
212204
}
213205
}

src/Renci.SshNet/PasswordConnectionInfo.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,5 @@ protected virtual void Dispose(bool disposing)
291291
_isDisposed = true;
292292
}
293293
}
294-
295-
/// <summary>
296-
/// Finalizes an instance of the <see cref="PasswordConnectionInfo"/> class.
297-
/// </summary>
298-
~PasswordConnectionInfo()
299-
{
300-
Dispose(disposing: false);
301-
}
302294
}
303295
}

src/Renci.SshNet/PrivateKeyAuthenticationMethod.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,6 @@ protected virtual void Dispose(bool disposing)
191191
}
192192
}
193193

194-
/// <summary>
195-
/// Finalizes an instance of the <see cref="PrivateKeyAuthenticationMethod"/> class.
196-
/// </summary>
197-
~PrivateKeyAuthenticationMethod()
198-
{
199-
Dispose(disposing: false);
200-
}
201-
202194
private sealed class SignatureData : SshData
203195
{
204196
private readonly RequestMessagePublicKey _message;

src/Renci.SshNet/PrivateKeyConnectionInfo.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,5 @@ protected virtual void Dispose(bool disposing)
170170
_isDisposed = true;
171171
}
172172
}
173-
174-
/// <summary>
175-
/// Finalizes an instance of the <see cref="PrivateKeyConnectionInfo"/> class.
176-
/// </summary>
177-
~PrivateKeyConnectionInfo()
178-
{
179-
Dispose(disposing: false);
180-
}
181173
}
182174
}

src/Renci.SshNet/PrivateKeyFile.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,6 @@ protected virtual void Dispose(bool disposing)
669669
}
670670
}
671671

672-
/// <summary>
673-
/// Finalizes an instance of the <see cref="PrivateKeyFile"/> class.
674-
/// </summary>
675-
~PrivateKeyFile()
676-
{
677-
Dispose(disposing: false);
678-
}
679-
680672
private sealed class SshDataReader : SshData
681673
{
682674
public SshDataReader(byte[] data)

src/Renci.SshNet/Security/Cryptography/ED25519DigitalSignature.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,5 @@ protected virtual void Dispose(bool disposing)
8383
_isDisposed = true;
8484
}
8585
}
86-
87-
/// <summary>
88-
/// Finalizes an instance of the <see cref="ED25519DigitalSignature"/> class.
89-
/// </summary>
90-
~ED25519DigitalSignature()
91-
{
92-
Dispose(disposing: false);
93-
}
9486
}
9587
}

src/Renci.SshNet/Security/Cryptography/ED25519Key.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,5 @@ protected virtual void Dispose(bool disposing)
131131
_isDisposed = true;
132132
}
133133
}
134-
135-
/// <summary>
136-
/// Finalizes an instance of the <see cref="ED25519Key"/> class.
137-
/// </summary>
138-
~ED25519Key()
139-
{
140-
Dispose(disposing: false);
141-
}
142134
}
143135
}

src/Renci.SshNet/Security/KeyExchange.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -564,15 +564,6 @@ protected virtual void Dispose(bool disposing)
564564
{
565565
}
566566

567-
/// <summary>
568-
/// Releases unmanaged resources and performs other cleanup operations before the
569-
/// <see cref="KeyExchange"/> is reclaimed by garbage collection.
570-
/// </summary>
571-
~KeyExchange()
572-
{
573-
Dispose(disposing: false);
574-
}
575-
576567
#endregion
577568
}
578569
}

src/Renci.SshNet/Session.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,14 +2253,6 @@ protected virtual void Dispose(bool disposing)
22532253
}
22542254
}
22552255

2256-
/// <summary>
2257-
/// Finalizes an instance of the <see cref="Session"/> class.
2258-
/// </summary>
2259-
~Session()
2260-
{
2261-
Dispose(disposing: false);
2262-
}
2263-
22642256
/// <summary>
22652257
/// Gets the connection info.
22662258
/// </summary>

src/Renci.SshNet/Sftp/SftpFileReader.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ public byte[] Read()
219219
return read;
220220
}
221221

222-
~SftpFileReader()
223-
{
224-
Dispose(disposing: false);
225-
}
226-
227222
public void Dispose()
228223
{
229224
Dispose(disposing: true);

src/Renci.SshNet/Sftp/SftpFileStream.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,6 @@ internal static async Task<SftpFileStream> OpenAsync(ISftpSession session, strin
439439
return new SftpFileStream(session, path, access, bufferSize, handle, position);
440440
}
441441

442-
/// <summary>
443-
/// Finalizes an instance of the <see cref="SftpFileStream"/> class.
444-
/// </summary>
445-
~SftpFileStream()
446-
{
447-
Dispose(disposing: false);
448-
}
449-
450442
/// <summary>
451443
/// Clears all buffers for this stream and causes any buffered data to be written to the file.
452444
/// </summary>

src/Renci.SshNet/Shell.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,5 @@ protected virtual void Dispose(bool disposing)
350350
_disposed = true;
351351
}
352352
}
353-
354-
/// <summary>
355-
/// Finalizes an instance of the <see cref="Shell"/> class.
356-
/// </summary>
357-
~Shell()
358-
{
359-
Dispose(disposing: false);
360-
}
361353
}
362354
}

src/Renci.SshNet/SubsystemSession.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,6 @@ protected virtual void Dispose(bool disposing)
537537
}
538538
}
539539

540-
/// <summary>
541-
/// Finalizes an instance of the <see cref="SubsystemSession" /> class.
542-
/// </summary>
543-
~SubsystemSession()
544-
{
545-
Dispose(disposing: false);
546-
}
547-
548540
private void EnsureNotDisposed()
549541
{
550542
#if NET7_0_OR_GREATER

0 commit comments

Comments
 (0)