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_r312722564
 
 

 ##########
 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:
   @szhem 
   hi,
   In your commet " reassign the reference of its sub-iterator to the empty 
iterator ..."
   
   I don't understand why reassigning iter would take effect on original 
sub-iterator .
   can you explain it more?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to