I followed the example in the samples on displaying a sub-window with close button by attaching it to an application. I wanted some text on the main window to be modified when the sub-window is closed.
The button click listener of the sub-window would remove the sub-window from the application.
And the Window.CloseListener, added to the sub-window, would modify the text in the main window.
But my presumptions were wrong.
- removing the sub-window from the application (by button click listener) does not “close” the window and therefore, Window.CloseListener would not be run.
- closing the sub-window will not remove it from the application, when I close the window thro the X on the top right corner.
Am I correct?
Therefore, I had to code the removal and text modification in both the button click and sub-window close listeners.
That kept me thinking …
if I keep on displaying messages on a sub-window which I close with the X, the number of unused closed windows being attached to the application would keep on increasing, and causing a memory leak. And I must write Window.CloseListener to remove a window when it is closed.
The answer I need is - does closing the window remove and destroy the window so that I do not need to write a removal routine in the close listener?
if I remove the window using the button then the button listener removes the window without closing it? Would I have to explicitly close the window in the button listener to avert a memory leak.
The second answer I need is - does removing a window would also “close” it too?
I am asking this because my application has quite a number of windows and layouts that are routinely added and removed or opened and closed. Usually, after a number of testing opening this part of my application, an out of memory exception results. I would like to know if I am looking at the correct source of my memory leak.