mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-30 20:18:08 +00:00
Java - Fixed a reference counting bug in the OrtEnvironment close method. Added a unit test for the bug.
This commit is contained in:
parent
7bb5c357a8
commit
4cc0031177
2 changed files with 13 additions and 1 deletions
|
|
@ -248,7 +248,6 @@ public class OrtEnvironment implements AutoCloseable {
|
|||
*/
|
||||
@Override
|
||||
public synchronized void close() throws OrtException {
|
||||
closed = true;
|
||||
synchronized (refCount) {
|
||||
int curCount = refCount.get();
|
||||
if (curCount != 0) {
|
||||
|
|
@ -256,6 +255,7 @@ public class OrtEnvironment implements AutoCloseable {
|
|||
}
|
||||
if (curCount == 1) {
|
||||
close(OnnxRuntime.ortApiHandle, nativeHandle);
|
||||
closed = true;
|
||||
INSTANCE = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import org.junit.jupiter.api.Test;
|
|||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
|
|
@ -70,6 +71,17 @@ public class InferenceTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatedCloseTest() throws OrtException {
|
||||
OrtEnvironment env = OrtEnvironment.getEnvironment("repeatedCloseTest");
|
||||
try (OrtEnvironment otherEnv = OrtEnvironment.getEnvironment()) {
|
||||
assertFalse(otherEnv.isClosed());
|
||||
}
|
||||
assertFalse(env.isClosed());
|
||||
env.close();
|
||||
assertTrue(env.isClosed());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSessionFromPath() throws OrtException {
|
||||
String modelPath = resourcePath.resolve("squeezenet.onnx").toString();
|
||||
|
|
|
|||
Loading…
Reference in a new issue