开发者

JPanel held by JNI Global reference causing OOM Exceptions

开发者 https://www.devze.com 2023-01-28 14:18 出处:网络
I wish i had more context to my question, but unfortunately, I\'m posting this question out of desperation. I am unable to reproduce this with a smaller application, as I wish i could post it here. Un

I wish i had more context to my question, but unfortunately, I'm posting this question out of desperation. I am unable to reproduce this with a smaller application, as I wish i could post it here. Unfortunately, all i can do is try to explain my symptoms, and hope that someone out there has seen something similar.

I have a purely java application, which is getting OutOfMemoryExceptions on some client machines. Im providing 400mb of java heap space, but unfortunately, we're still see this issue. Grabbing a heap dump from my application before it crashes, i can see that there are an unusually large number of JPanel objects. Looking at the heap dump, what's interesting is the ONLY incoming reference to my panel is a "JNI Global Reference". Whats confusing to me is, Why would there be a JNI global reference to a JPanel in the first place? I only have ONE Frame. Under开发者_运维技巧 what circumstances would java need to create a global JNI reference to a JPanel?

Although I have one theory, its not based on anything I've read, but i get the feeling that the finalizer thread is blocked. Unfortunately, i don't have a thread dump to prove this. My theory is, my jpanel was queued to be garbage collected, however, once it entered the queue, the queue itself is unable to process this.

Is there anybody out there willing to share their theory or gut instinct? Since i can't reproduce this on my machine, I'm a bit handcuffed with respect to analysing this theory. However if someone out there is willing to give me another investigation route, I would be more than grateful.

EDIT: I have a small update about this. My application also uses drag and drop, and analyzing the heap dump some more, i noticed that there are as many java.awt.datatransfer.Transferable object (which passes my JPanel as part of the transferable), as there are JPanels that have not been cleaned up. Whats interesting, is that the only reference to the Transferable object is again, the JNI Global. It makes me wonder if the finalizer isn't blocked on cleaning up the JPanels, but on cleaning up the drag and drop transferable object.

EDIT: So In case anybody was interested, I believe I've determined the problem. So something i left out in the original post was out application embeds an HTML page using the windows IE COM libraries (using some third party library). Anyways, it turns out that either the third-party library, or the IE COM library itself grabs a JNI global reference while drag and drops occur. Unfortuantely, I don't have a work around for this issue, but I'd like to thank all those that have sent me suggestions while investigating this issue.


Assuming the Java Native Interface code is not your own, you may need to dispose() an errant graphics context "if it was created directly from a component or another Graphics object." This RotatableImage is an example that would leak without dispose().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号