Explorar o código

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

David Karnok %!s(int64=7) %!d(string=hai) anos
pai
achega
0b37a6aaad
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  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[]> 
         {
-            private readonly List<TSource> _list;
+            private List<TSource> _list;
 
             public _(IObserver<TSource[]> observer)
                 : base(observer)
@@ -34,9 +34,17 @@ namespace System.Reactive.Linq.ObservableImpl
                 _list.Add(value);
             }
 
+            public override void OnError(Exception error)
+            {
+                _list = null;
+                base.OnError(error);
+            }
+
             public override void OnCompleted()
             {
-                ForwardOnNext(_list.ToArray());
+                var list = _list;
+                _list = null;
+                ForwardOnNext(list.ToArray());
                 ForwardOnCompleted();
             }
         }