1

I'm seeing a memory leak in a java swing application. It's leaking LightweightFocusRequest objects connected under a HeavyweightFocusRequest in the DefaultKeyboardFocusManager. The application runs in an undecorated, alwaysontop JFrame. (i.e. full-screen).

The application appears to have focus. Users can click on it, and interact (all via mouse as it's a kiosk w/o a keyboard). But each interaction that produces a focus request such as showing a dialog, etc, leaks the LightweightFocusRequest object.

I was able to determine this via a heap-dump and the Eclipse Memory Analyzer tool. As a workaround, if the application is switched out of fullscreen mode and the user clicks on another app, and back on our app, then the leaked memory is reclaimed as the outstanding focus request events are all cleared.

It's acting as if the java application missed a focus gained event.

I've seen this problem under Windows with jre version 1.6.0_35 (and _27). Not all users suffer the issue, so I don't know what other factors contribute. I also can't say for sure that it happens or doesn't happen under the latest 1.7 JRE, as the JRE versions used are beyond my control. The majority (90%+) are 1.6.0_20 to 1.6.0_39.

All attempts to reproduce the problem have failed.

My next strategy as a workaround is to add a check in the application on a timer to examine the focus request queue via reflection. If it looks like it's leaking (100+ outstanding items?) then create another window, give it focus, re-request focus and close the other temp window.

Has anyone seen a problem like this before or have a better workaround? My searching for something similar in the java bugdb and google wasn't fruitful.

Chris Holt
  • 655
  • 1
  • 6
  • 19
  • Check for EDT violations using one of the approaches cited [here](http://stackoverflow.com/q/7787998/230513); see also this [Q&A](http://stackoverflow.com/q/6309407/2305130). – trashgod Apr 21 '14 at 16:47
  • I used the AspectJ approach to check for EDT violations, and came up empty. I've always been very careful to not introduce any EDT issues. The only one I had years ago was constructing components before showing them, that's been resolved for a long time now. – Chris Holt Apr 21 '14 at 19:21
  • Sounds good; more candidates [here](http://stackoverflow.com/a/2486200/230513). – trashgod Apr 21 '14 at 19:29

0 Answers0