我有一个eclipse插件,它使用Jacob连接到一个COM组件。但是在我完全关闭插件后,.exe文件停留在Windows进程中。
我使用 ComThread.InitMTA c $ c>用于初始化,并确保在关闭应用程序之前为每个创建的COM对象调用 SafeRelease(),并调用 ComThread.Release
解决方案与TD2JIRA转换器有相同的问题。最终不得不修补一个Jacob文件释放对象。之后,一切顺利。
我的客户端logout()方法中的代码现在如下所示:
try { Class rot = ROT.class; 方法clear = rot.getDeclaredMethod(clearObjects,new Class [] {}); clear.setAccessible(true); clear.invoke(null,new Object [] {}); } catch(Exception ex){ ex.printStackTrace(); }ROT类最初无法访问,AFAIR。
更新
在Jacob发布资源的正确方法是调用
ComThread.InitSTA(); //或ComThread.InitMTA() ... ComThread.Release();不好的是,有时它不会帮助。尽管Jacob调用本地方法release(),内存(甚至Java内存,但JVM进程内存)不可控制地增长。
I have an eclipse plugin, which connects to a COM component using Jacob. But after I close the plugin entirely, the .exe file stays hanging in Windows processes.
I use ComThread.InitMTA(true) for initialization and make sure that SafeRelease() is called for every COM object I created before closing the app and I call ComThread.Release() at the very end.
Do I leave something undone?
解决方案Had the same problem with TD2JIRA converter. Eventually had to patch one of the Jacob files to release the objects. After that all went smooth.
The code in my client logout() method now looks like this:
try { Class rot = ROT.class; Method clear = rot.getDeclaredMethod("clearObjects", new Class[]{}); clear.setAccessible(true); clear.invoke(null, new Object[]{}); } catch( Exception ex ) { ex.printStackTrace(); }The ROT class wasn't accessible initially, AFAIR.
Update
The correct way to release resources in Jacob is to call
ComThread.InitSTA(); // or ComThread.InitMTA() ... ComThread.Release();Bad thing though is that sometimes it doesn't help. Despite Jacob calls native method release(), the memory (not even Java memory, but JVM process memory) grows uncontrollably.
更多推荐
JACOB不正确释放对象
发布评论