-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix for Memory Leak #659 * Update MemoryLeakTests.cs * Remove ReadOnlyCollectionPooled Use ReadOnlyDisposableCollection
- Loading branch information
1 parent
efe8b22
commit 3834d5e
Showing
10 changed files
with
102 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 0 additions & 112 deletions
112
src/ReactiveUI.Validation/Collections/ReadOnlyCollectionPooled.cs
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
src/ReactiveUI.Validation/Collections/ReadOnlyDisposableCollection{T}.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved. | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
|
||
namespace ReactiveUI.Validation.Collections; | ||
|
||
internal sealed class ReadOnlyDisposableCollection<T>(IEnumerable<T> items) : IReadOnlyCollection<T>, IDisposable | ||
{ | ||
private readonly ImmutableList<T> _immutableList = ImmutableList.CreateRange(items); | ||
private bool _disposedValue; | ||
|
||
/// <summary> | ||
/// Gets the number of elements in the collection. | ||
/// </summary> | ||
public int Count => _immutableList.Count; | ||
|
||
/// <summary> | ||
/// Returns an enumerator that iterates through the collection. | ||
/// </summary> | ||
/// <returns> | ||
/// An enumerator that can be used to iterate through the collection. | ||
/// </returns> | ||
public IEnumerator<T> GetEnumerator() => _immutableList.GetEnumerator(); | ||
|
||
/// <summary> | ||
/// Returns an enumerator that iterates through a collection. | ||
/// </summary> | ||
/// <returns> | ||
/// An <see cref="T:System.Collections.IEnumerator"></see> object that can be used to iterate through the collection. | ||
/// </returns> | ||
IEnumerator IEnumerable.GetEnumerator() => _immutableList.GetEnumerator(); | ||
|
||
/// <summary> | ||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
Dispose(disposing: true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
private void Dispose(bool disposing) | ||
{ | ||
if (!_disposedValue) | ||
{ | ||
if (disposing) | ||
{ | ||
_immutableList.Clear(); | ||
} | ||
|
||
_disposedValue = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.