File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -248,14 +248,14 @@ public String toString() {
248248 */
249249 @ Override
250250 public synchronized void close () throws OrtException {
251- closed = true ;
252251 synchronized (refCount ) {
253252 int curCount = refCount .get ();
254253 if (curCount != 0 ) {
255254 refCount .decrementAndGet ();
256255 }
257256 if (curCount == 1 ) {
258257 close (OnnxRuntime .ortApiHandle , nativeHandle );
258+ closed = true ;
259259 INSTANCE = null ;
260260 }
261261 }
Original file line number Diff line number Diff line change 1717import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
1818import static org .junit .jupiter .api .Assertions .assertEquals ;
1919import static org .junit .jupiter .api .Assertions .assertNotNull ;
20+ import static org .junit .jupiter .api .Assertions .assertFalse ;
2021import static org .junit .jupiter .api .Assertions .assertTrue ;
2122import static org .junit .jupiter .api .Assertions .fail ;
2223
@@ -70,6 +71,17 @@ public class InferenceTest {
7071 }
7172 }
7273
74+ @ Test
75+ public void repeatedCloseTest () throws OrtException {
76+ OrtEnvironment env = OrtEnvironment .getEnvironment ("repeatedCloseTest" );
77+ try (OrtEnvironment otherEnv = OrtEnvironment .getEnvironment ()) {
78+ assertFalse (otherEnv .isClosed ());
79+ }
80+ assertFalse (env .isClosed ());
81+ env .close ();
82+ assertTrue (env .isClosed ());
83+ }
84+
7385 @ Test
7486 public void createSessionFromPath () throws OrtException {
7587 String modelPath = resourcePath .resolve ("squeezenet.onnx" ).toString ();
You can’t perform that action at this time.
0 commit comments