Why do you have to deal with () an out of range Java awt. Window?

One of the memory leaks I found in my application was Java awt. Window. All windows specific static field that tracks each instantiated window We have dialog boxes created, used, and then forgotten, and expect them to disappear and be garbage collected This private field remains scoped indefinitely until the dispose () method is called By definition, we cannot do this when we are out of range

I don't understand why this is designed like this This seems to be contrary to the spirit of garbage collection. It is necessary to let the system know when I have completed a window object Obviously I finished it because it was out of range

I understand what the dispose () method is doing: getting rid of the system peer object I understand that this is outside Java. You need some methods to do this, and swing should not just lose tracking of these objects, otherwise there will be memory leakage But what can I do by keeping a reference to my window when I'll never use it again?

Can anyone explain why this is necessary?

Solution

I hate to say, but it's just how GUI works

Windows is non blocking It means that once you create a code in the code, your code will continue to execute

This means that your window may go out of scope immediately after creation, unless you explicitly store the reference elsewhere The window is still on the screen

It also means that you need some other way to get rid of it when you finish it Enter the Window dispose () method to call it from a listener in Window.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>