ChenjunZou commented on a change in pull request #23083: [SPARK-26114][CORE] 
ExternalSorter's readingIterator field leak
URL: https://github.com/apache/spark/pull/23083#discussion_r312770904
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/util/CompletionIterator.scala
 ##########
 @@ -25,11 +25,14 @@ private[spark]
 abstract class CompletionIterator[ +A, +I <: Iterator[A]](sub: I) extends 
Iterator[A] {
 
   private[this] var completed = false
-  def next(): A = sub.next()
+  private[this] var iter = sub
+  def next(): A = iter.next()
   def hasNext: Boolean = {
-    val r = sub.hasNext
+    val r = iter.hasNext
     if (!r && !completed) {
       completed = true
+      // reassign to release resources of highly resource consuming iterators 
early
+      iter = Iterator.empty.asInstanceOf[I]
 
 Review comment:
   Thanks, szhem :)
   your UT explains all. 
   at first I misunderstand sub as CompletionIterator(val sub)
   Hided, well done!
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to