My team is working on analyzing our Swing application to make sure everything is being garbage collected when it's no longer being used. We're running into an odd problem.
We are simply opening a new window (JFrame
) and closing it. This frame contains an EmptyPanel
class (which contains a short message saying there is no data) and a custom JMeunBar
class. We don't interact with this at all - just close the window immediately.
Then, we force a garbage collection and do a heap dump.
Upon analysis of the heap dump, the JMenuBar
isn't being garbage collected. It's being kept open from the GC Root sun.awt.AppContext
.
How do we clean this up? Or is this something we don't have to worry about for some reason? We want to be diligent making sure our application cleans up after itself, but we don't want to spin our wheels on this either.
AppContext.mainAppContext
contains a HashMap which contains a BasicPopupMenuUI.MenuKeyboardHelper
instance. Inside this is a ComponentInputMapUIResource.menuInputMap
which has this JMenuBar
as a component.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…