let's consider swing java application that opens and closes many frames during running.
Frames can be open, closed, reopen again. Many different frames can be open at the same time.
Each frame is considered as a spring prototype scoped bean. But it seems that it doesn't even matter here, because spring doesn't manage the references of prototype scoped beans.
The problem arises when user closes frame. What happens when closing:
@Override
public void closeFrame(OurFrame frame) {
if (isFrameOpened(frame)) {
OurFrame openFrame = activeFrames.get(frame);
frame.setVisible(false);
frame.dispose();
activeFrames.remove(false);
frame = null;
}
}
activeFrames keep all currently open frames. closeFrame(...) method is invoked by WindowAdapter when user decides to close window.
After all, as sampler says, the closed frames still hang in memory. Heap increases and if you try to open same frame second time, application creates new, another instance, still keeping all the hanging ghosts in memory.
In the end of the day, there can be a lot of them, what makes the problem... There are no frames that are eligible for garbage collector at all.
There are no explicit references referring to closed frames. VisualVM says that there are two referents: WeakReference and WeakHashMap$Entry.
Does anybody have any clue ?
Regards, Dreando