File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -23,9 +23,13 @@ public final class JavaVirtualMachine: @unchecked Sendable {
2323 /// The Java virtual machine instance.
2424 private let jvm : JavaVMPointer
2525
26+ /// Whether to destroy the JVM on deinit.
27+ private let destroyOnDeinit : Bool
28+
2629 /// Adopt an existing JVM pointer.
2730 private init ( adoptingJVM jvm: JavaVMPointer ) {
2831 self . jvm = jvm
32+ self . destroyOnDeinit = false
2933 }
3034
3135 /// Initialize a new Java virtual machine instance.
@@ -90,12 +94,15 @@ public final class JavaVirtualMachine: @unchecked Sendable {
9094 }
9195
9296 self . jvm = jvm!
97+ self . destroyOnDeinit = true
9398 }
9499
95100 deinit {
96- // Destroy the JVM.
97- if jvm. pointee!. pointee. DestroyJavaVM ( jvm) != JNI_OK {
98- fatalError ( " Failed to destroy the JVM. " )
101+ if destroyOnDeinit {
102+ // Destroy the JVM.
103+ if jvm. pointee!. pointee. DestroyJavaVM ( jvm) != JNI_OK {
104+ fatalError ( " Failed to destroy the JVM. " )
105+ }
99106 }
100107 }
101108}
You can’t perform that action at this time.
0 commit comments