JACOB不正确释放对象 [英] JACOB doesn't release the objects properly

查看:1764
本文介绍了JACOB不正确释放对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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不正确释放对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆