Skip to content

Commit 9c285c7

Browse files
j-bakerrobert3005
authored andcommitted
[SPARK-21319][SQL] Fix memory leak in UnsafeExternalRowSorter.RowComparator (apache-spark-on-k8s#222)
* SPARK-21319: Fix memory leak in UnsafeExternalRowSorter.RowComparator UnsafeExternalRowSorter.RowComparator contains references to the objects backing the last arrays sorted. This causes memory leaks, since those objects become deallocated but are still live. We make sure to unset them. * Symmetric fix for UnsafeKVExternalSorter
1 parent 8be7fd4 commit 9c285c7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sql/catalyst/src/main/java/org/apache/spark/sql/execution/UnsafeExternalRowSorter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,10 @@ public int compare(Object baseObj1, long baseOff1, Object baseObj2, long baseOff
211211
// TODO: Why are the sizes -1?
212212
row1.pointTo(baseObj1, baseOff1, -1);
213213
row2.pointTo(baseObj2, baseOff2, -1);
214-
return ordering.compare(row1, row2);
214+
int comparison = ordering.compare(row1, row2);
215+
row1.pointTo(null, 0L, -1);
216+
row2.pointTo(null, 0L, -1);
217+
return comparison;
215218
}
216219
}
217220
}

sql/core/src/main/java/org/apache/spark/sql/execution/UnsafeKVExternalSorter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ public int compare(Object baseObj1, long baseOff1, Object baseObj2, long baseOff
242242
// into the row.
243243
row1.pointTo(baseObj1, baseOff1 + 4, -1);
244244
row2.pointTo(baseObj2, baseOff2 + 4, -1);
245-
return ordering.compare(row1, row2);
245+
int comparison = ordering.compare(row1, row2);
246+
row1.pointTo(null, 0L, -1);
247+
row2.pointTo(null, 0L, -1);
248+
return comparison;
246249
}
247250
}
248251

0 commit comments

Comments
 (0)