Browse Source
Avoid memory leak by clearing the shared array pool of LightweightObservableBase (#19167)
pull/19188/head
walterlv
7 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
3 additions and
1 deletions
-
src/Avalonia.Base/Reactive/LightweightObservableBase.cs
|
|
|
@ -20,7 +20,7 @@ namespace Avalonia.Reactive |
|
|
|
private List<IObserver<T>>? _observers = new List<IObserver<T>>(); |
|
|
|
|
|
|
|
public bool HasObservers => _observers?.Count > 0; |
|
|
|
|
|
|
|
|
|
|
|
public IDisposable Subscribe(IObserver<T> observer) |
|
|
|
{ |
|
|
|
_ = observer ?? throw new ArgumentNullException(nameof(observer)); |
|
|
|
@ -168,6 +168,8 @@ namespace Avalonia.Reactive |
|
|
|
for(int i = 0; i < count; i++) |
|
|
|
{ |
|
|
|
observers[i].OnNext(value); |
|
|
|
// Avoid memory leak by clearing the reference.
|
|
|
|
observers[i] = null!; |
|
|
|
} |
|
|
|
|
|
|
|
ArrayPool<IObserver<T>>.Shared.Return(observers); |
|
|
|
|