JACOB 没有正确释放对象

JACOB doesn#39;t release the objects properly(JACOB 没有正确释放对象)
本文介绍了JACOB 没有正确释放对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 Eclipse 插件,它使用 Jacob 连接到一个 COM 组件.但是在我完全关闭插件后,.exe 文件仍然挂在 Windows 进程中.

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.

我使用 ComThread.InitMTA(true) 进行初始化,并确保在关闭应用程序之前为我创建的每个 COM 对象调用 SafeRelease() 并调用 <代码>ComThread.Release() 在最后.

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?

推荐答案

TD2JIRA 转换器也有同样的问题.最终不得不修补其中一个 Jacob 文件以释放对象.之后一切顺利.

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.

我的客户端 logout() 方法中的代码现在如下所示:

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();
}

最初无法访问 ROT 类,AFAIR.

The ROT class wasn't accessible initially, AFAIR.

更新

Jacob中释放资源的正确方法是调用

The correct way to release resources in Jacob is to call

ComThread.InitSTA(); // or ComThread.InitMTA()
...
ComThread.Release();

但不好的是,有时它无济于事.尽管 Jacob 调用了本机方法 release(),但内存(甚至不是 Java 内存,而是 JVM 进程内存)却无法控制地增长.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Sending a keyboard event from java to any application (on-screen-keyboard)(将键盘事件从 java 发送到任何应用程序(屏幕键盘))
How to make JComboBox selected item not changed when scrolling through its popuplist using keyboard(使用键盘滚动其弹出列表时如何使 JComboBox 所选项目不更改)
Capturing keystrokes without focus(在没有焦点的情况下捕获击键)
How can I position a layout right above the android on-screen keyboard?(如何将布局放置在 android 屏幕键盘的正上方?)
How to check for key being held down on startup in Java(如何检查在Java中启动时按住的键)
Android - Get keyboard key press(Android - 获取键盘按键)