Skip to content

Commit

Permalink
Ensure proper disposal of _nhlPlayerApi resources
Browse files Browse the repository at this point in the history
Modified the Dispose and DisposeAsync methods in the NhlApi class to include calls to _nhlPlayerApi.Dispose() before GC.SuppressFinalize(this). This ensures that _nhlPlayerApi resources are properly disposed of, preventing potential resource leaks both synchronously and asynchronously.
  • Loading branch information
Afischbacher committed Mar 8, 2025
1 parent 2b506c6 commit aec207d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Nhl.Api/Src/Api/NhlApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -736,15 +736,21 @@ public async Task<PlayerDraftYear> GetPlayerDraftRankingByYearAsync(string seaso
/// <summary>
/// Releases and disposes all unused or garbage collected resources for the Nhl.Api
/// </summary>
public void Dispose() =>
public void Dispose()
{
_nhlPlayerApi.Dispose();
GC.SuppressFinalize(this);
}

/// <summary>
/// Releases and disposes all unused or garbage collected resources for the Nhl.Api asynchronously
/// </summary>
/// <returns>The await-able result of the asynchronous operation</returns>
public async ValueTask DisposeAsync() =>
await Task.Run(() => GC.SuppressFinalize(this));
public async ValueTask DisposeAsync()
{
_nhlPlayerApi.Dispose();
await Task.Run(() => GC.SuppressFinalize(this));
}

/// <summary>
/// Returns the current NHL playofff schedule for the current season
Expand Down

0 comments on commit aec207d

Please sign in to comment.