Преглед изворни кода

ToArray(): avoid retention of the list beyond the conversion (#701)

David Karnok пре 7 година
родитељ
комит
0b37a6aaad
1 измењених фајлова са 10 додато и 2 уклоњено
  1. 10 2
      Rx.NET/Source/src/System.Reactive/Linq/Observable/ToArray.cs

+ 10 - 2
Rx.NET/Source/src/System.Reactive/Linq/Observable/ToArray.cs

@@ -21,7 +21,7 @@ namespace System.Reactive.Linq.ObservableImpl
 
 
         internal sealed class _ : Sink<TSource, TSource[]> 
         internal sealed class _ : Sink<TSource, TSource[]> 
         {
         {
-            private readonly List<TSource> _list;
+            private List<TSource> _list;
 
 
             public _(IObserver<TSource[]> observer)
             public _(IObserver<TSource[]> observer)
                 : base(observer)
                 : base(observer)
@@ -34,9 +34,17 @@ namespace System.Reactive.Linq.ObservableImpl
                 _list.Add(value);
                 _list.Add(value);
             }
             }
 
 
+            public override void OnError(Exception error)
+            {
+                _list = null;
+                base.OnError(error);
+            }
+
             public override void OnCompleted()
             public override void OnCompleted()
             {
             {
-                ForwardOnNext(_list.ToArray());
+                var list = _list;
+                _list = null;
+                ForwardOnNext(list.ToArray());
                 ForwardOnCompleted();
                 ForwardOnCompleted();
             }
             }
         }
         }