Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
fix memory leakage in native columnartorow (#1044)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
  • Loading branch information
zhouyuan authored Jul 29, 2022
1 parent c288195 commit 43dcdda
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.apache.spark.sql.execution.datasources.v2.arrow.SparkMemoryUtils
import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
import org.apache.spark.sql.execution.{CodegenSupport, ColumnarToRowTransition, SparkPlan}
import org.apache.spark.sql.types._
import org.apache.spark.TaskContext

import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
Expand Down Expand Up @@ -146,13 +147,21 @@ case class ArrowColumnarToRowExec(child: SparkPlan) extends ColumnarToRowTransit
var rowId = 0
val row = new UnsafeRow(batch.numCols())
var closed = false

TaskContext.get().addTaskCompletionListener[Unit](_ => {
if (!closed) {
jniWrapper.nativeClose(info.instanceID)
closed = true
}
})

override def hasNext: Boolean = {
val result = rowId < batch.numRows()
if (!result && !closed) {
jniWrapper.nativeClose(info.instanceID)
closed = true
}
return result
result
}

override def next: UnsafeRow = {
Expand Down

0 comments on commit 43dcdda

Please sign in to comment.