Skip to content

Commit

Permalink
Closed column view to avoid memory leak (#8202)
Browse files Browse the repository at this point in the history
fixes #8177

Authors:
  - Raza Jafri (https://github.com/razajafri)

Approvers:
  - Jason Lowe (https://github.com/jlowe)

URL: #8202
  • Loading branch information
razajafri authored May 11, 2021
1 parent 9a063b6 commit 2c70f1d
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions java/src/main/java/ai/rapids/cudf/ColumnView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1457,23 +1457,32 @@ public ColumnView replaceChildrenWithViews(int[] indices,
map.put(indices[index], views[index]);
});
List<ColumnView> newChildren = new ArrayList<>(getNumChildren());
IntStream.range(0, getNumChildren()).forEach(i -> {
ColumnView view = map.remove(i);
ColumnView child = getChildColumnView(i);
if (view == null) {
newChildren.add(child);
} else {
if (child.getRowCount() != view.getRowCount()) {
throw new IllegalArgumentException("Child row count doesn't match the old child");
List<ColumnView> toClose = new ArrayList<>(getNumChildren());
try {
IntStream.range(0, getNumChildren()).forEach(i -> {
ColumnView view = map.remove(i);
ColumnView child = getChildColumnView(i);
toClose.add(child);
if (view == null) {
newChildren.add(child);
} else {
if (child.getRowCount() != view.getRowCount()) {
throw new IllegalArgumentException("Child row count doesn't match the old child");
}
newChildren.add(view);
}
newChildren.add(view);
});
if (!map.isEmpty()) {
throw new IllegalArgumentException("One or more invalid child indices passed to be " +
"replaced");
}
return new ColumnView(type, getRowCount(), Optional.of(getNullCount()), getValid(),
getOffsets(), newChildren.stream().toArray(n -> new ColumnView[n]));
} finally {
for (ColumnView columnView: toClose) {
columnView.close();
}
});
if (!map.isEmpty()) {
throw new IllegalArgumentException("One or more invalid child indices passed to be replaced");
}
return new ColumnView(type, getRowCount(), Optional.of(getNullCount()), getValid(),
getOffsets(), newChildren.stream().toArray(n -> new ColumnView[n]));
}

/**
Expand Down

0 comments on commit 2c70f1d

Please sign in to comment.