Skip to content

Commit

Permalink
Fix memory leak on empty inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed Jul 6, 2015
1 parent d246e29 commit 6890863
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ private void cleanupResources() {
Iterator<InternalRow> sort() throws IOException {
try {
final UnsafeSorterIterator sortedIterator = sorter.getSortedIterator();
if (!sortedIterator.hasNext()) {
// Since we won't ever call next() on an empty iterator, we need to clean up resources
// here in order to prevent memory leaks.
cleanupResources();
}
return new AbstractScalaRowIterator() {

private final int numFields = schema.length();
Expand Down Expand Up @@ -141,7 +146,7 @@ public InternalRow next() {
);
row.backingArray = rowDataCopy;
row.pointTo(rowDataCopy, PlatformDependent.BYTE_ARRAY_OFFSET, numFields, objPool);
sorter.freeMemory();
cleanupResources();
return row;
}
} catch (IOException e) {
Expand Down

0 comments on commit 6890863

Please sign in to comment.