I have a JButton “MAIN_BUTTON” in a window. When it is clicked it starts a new thread every time.
The newly created thread in turn calls a method of another class that displays a new “child_window”*(using a constructor and creating an object of it)*. This window has two buttons on it “accept” and “reject”. When any of these buttons are pressed then some work is done and this window is closed.
Now I want to know after stopping the thread whether the “CHILD_WINDOW” object is destroyed or it still exists in memory.
In the general case, the answer depends on your what the thread has done with the reference to the object. If it has put it somewhere that means that it is “reachable”, then the object will still exist. If not, it may cease to exist, depending on whether and when the GC gets around to collecting it.
I’m not entirely sure what happens in the case of a
Windowobject. I suspect that there may be some reference to the object in the graphics context (or something) that means that theWindowwill remain reachable until some application-level code explicitly closes or disposes it. (Otherwise, you’d hear stories of Swing windows disappearing randomly … due to being reclaimed by the garbage collector.)