Java析构函数
我用JNA写了一个操作进程的程序,类析构时需要用CloseHandle()函数关闭进程句柄
大概这么写
使用时:
但这样写的话感觉有点麻烦,有没有什么更为便捷的方法?
大概这么写
class Process {
private HANDLE handle
public Process(HANDLE h) {
handle = h;
}
......
@Override
public void finalize(){
CloseHandle(handle);
}
}
使用时:
// in method main()
Process p = new Process(handle);
...
p = null;
System.gc();
但这样写的话感觉有点麻烦,有没有什么更为便捷的方法?
...全文


Java SE
