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 {
23
23
/// The Java virtual machine instance.
24
24
private let jvm : JavaVMPointer
25
25
26
+ /// Whether to destroy the JVM on deinit.
27
+ private let destroyOnDeinit : Bool
28
+
26
29
/// Adopt an existing JVM pointer.
27
30
private init ( adoptingJVM jvm: JavaVMPointer ) {
28
31
self . jvm = jvm
32
+ self . destroyOnDeinit = false
29
33
}
30
34
31
35
/// Initialize a new Java virtual machine instance.
@@ -90,12 +94,15 @@ public final class JavaVirtualMachine: @unchecked Sendable {
90
94
}
91
95
92
96
self . jvm = jvm!
97
+ self . destroyOnDeinit = true
93
98
}
94
99
95
100
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
+ }
99
106
}
100
107
}
101
108
}
You can’t perform that action at this time.
0 commit comments