Skip to content

Commit c4ec0bb

Browse files
committed
close tensors i forgot to close
1 parent 790f7a4 commit c4ec0bb

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/io/bioimage/modelrunner/tensorflow/v2/api020/Tensorflow2Interface.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,10 @@ public <T extends RealType<T> & NativeType<T>, R extends RealType<R> & NativeTyp
344344
for (int i = 0; i < resultPatchTensors.size(); i++) {
345345
try {
346346
rais.add(ImgLib2Builder.build(resultPatchTensors.get(i)));
347+
resultPatchTensors.get(i).close();
347348
} catch (IllegalArgumentException ex) {
348-
for (org.tensorflow.Tensor<?> tt : resultPatchTensors)
349-
tt.close();
349+
for (int j = i; j < resultPatchTensors.size(); j++)
350+
resultPatchTensors.get(j).close();
350351
throw new RunModelException(Types.stackTrace(ex));
351352
}
352353
}
@@ -426,6 +427,9 @@ protected List<String> inferenceFromShmas(List<String> inputs) throws IOExceptio
426427
ShmBuilder.build(resultPatchTensors.get(i), name, false);
427428
shmaNamesList.add(name);
428429
}
430+
for (org.tensorflow.Tensor<?> tt : resultPatchTensors) {
431+
tt.close();
432+
}
429433
return shmaNamesList;
430434
}
431435

0 commit comments

Comments
 (0)