Browse Source

ToDictionary(): clear the dictionary reference upon termination (#702)

David Karnok 7 years ago
parent
commit
7e316bb6d8
1 changed files with 11 additions and 2 deletions
  1. 11 2
      Rx.NET/Source/src/System.Reactive/Linq/Observable/ToDictionary.cs

+ 11 - 2
Rx.NET/Source/src/System.Reactive/Linq/Observable/ToDictionary.cs

@@ -29,7 +29,7 @@ namespace System.Reactive.Linq.ObservableImpl
         {
             private readonly Func<TSource, TKey> _keySelector;
             private readonly Func<TSource, TElement> _elementSelector;
-            private readonly Dictionary<TKey, TElement> _dictionary;
+            private Dictionary<TKey, TElement> _dictionary;
 
             public _(ToDictionary<TSource, TKey, TElement> parent, IObserver<IDictionary<TKey, TElement>> observer)
                 : base(observer)
@@ -47,13 +47,22 @@ namespace System.Reactive.Linq.ObservableImpl
                 }
                 catch (Exception ex)
                 {
+                    _dictionary = null;
                     ForwardOnError(ex);
                 }
             }
 
+            public override void OnError(Exception error)
+            {
+                _dictionary = null;
+                ForwardOnError(error);
+            }
+
             public override void OnCompleted()
             {
-                ForwardOnNext(_dictionary);
+                var dictionary = _dictionary;
+                _dictionary = null;
+                ForwardOnNext(dictionary);
                 ForwardOnCompleted();
             }
         }