問題描述
我有一個 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)
進行初始化,并確保在關閉應用程序之前為我創(chuàng)建的每個 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() 方法中的代碼現(xiàn)在如下所示:
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 沒有正確釋放對象的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!