デフォルトの実装は何もない:それは別のスレッドで必要とされている間に共有ネイティブリソースが1つのスレッドで削除されたよう
public class Object {
protected void finalize() throws Throwable { }
}
あなたの説明は鳴りません。 ネイティブのメソッド(java)をチェックして、ネイティブメモリスペースから何かを削除する必要があります。
Javaはネイティブコードで割り当てられたオブジェクトについて知らない。ネイティブコールでこれを手動で制御する必要があります。たとえば、
public class A {
private int id;
static {
// load native library
}
public A(int id) {
// create required native resources for this instance
allocateAContext(id)
}
// this method will create required native resources out of java heap
protected native void allocateAContext(int id);
// this method will remove allocated native resources
protected native void deleteAContext(int id);
@Override
protected void finalize() throws Throwable {
super.finalize();
// release native resources when garbage collector will remove A object
deleteAContext(id);
}
}
ありがとうございました。あなたの答えが私の質問にどう関係しているのか分かりません。これはJNIの基本ではなく、非常に特殊なコーナーケースです。 –