瀏覽代碼

ToList(): release reference to the list upon termination (#703)

David Karnok 7 年之前
父節點
當前提交
7a48dcea39
共有 1 個文件被更改,包括 10 次插入2 次删除
  1. 10 2
      Rx.NET/Source/src/System.Reactive/Linq/Observable/ToList.cs

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

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