0

I have a Java project which works with one dll library via COM. I have Windows 7 and I use 32bit Java 1.6. I use 2012/04/26 release of com4j as a bridge. It works.

The problem is that I have a serious memory leak which makes operation of my program almost impossible.

I have subscribed to some COM events. When the next event arrives I observe the raise of Heap memory used, and GC never helps to decrease it. If I use COM4J.cleanUp() - memory usage stops its growth, but the events no longer arrive. Heap memory used by my program raises very fast, while in fact no my own objects being allocated.

Snapshots difference in VisualVM: http://postimg.org/image/cxg77ft8j/

Heap Memory raise in VisualVM: http://postimg.org/image/m52g63b51/

Looks like the problem is with DirectByteBuffer, Cleaner, Variant and Finalizer instances. I do not create them by myself. This is something inside com4j.

Any suggestions?

MiamiBeach
  • 3,261
  • 6
  • 28
  • 54

1 Answers1

1

I am investigating memory leaks myself in a com4j project I am working on. From what I understand, Com4j starts a ComThread for every JavaThread that uses Com4j. All calls to Com4j are executed as tasks for that Thread. When the Thread exists, the resources are released and all COM-Wrappers are disposed off. COM4J.cleanUp() actually kills the ComThread for the current Java Thread, which explains, why the events you listen to stop coming.

I saw the same behavior in my project: the longer a ComThread runs, the more heap was used and never freed. When Com4j wrappers are disposed, they are not removed from the heap, as they remain in the live objects set of the ComThread.

Have a look at https://github.com/guykv/com4j/compare/Issue16. Merging that change to my com4j fork actually helped the Heap to remain stable.

Cheears.

mattes
  • 61
  • 7
  • Thanks a lot, mattes! I am happy that this project is still alive. – MiamiBeach Feb 04 '14 at 20:49
  • I use the following maven dependency: org.jvnet.com4j com4j 20120426-2 Looks like it is stale? Could you tell me how did you get your stable version of com4j: which maven artefact from which repo you used and what ELSE you have merged there? – MiamiBeach Feb 04 '14 at 20:52
  • Now I solve my problem in a very odd way: I just deactivate my old COM java object and recreate it in every 15 min :) After the listeners are disconnected GC succeeds. – MiamiBeach Feb 04 '14 at 20:55
  • The fix was not merged to the main repo yet, as far as I can see. I simply merged it myself in my local fork. – mattes Feb 24 '14 at 11:13