When you create a GUI element such as a JFrame like this
new JFrame(); // nothing pointing to it.
is this wrong because there is nothing pointing to it, so it will be garbage collected. I realize this works, but I want to make sure this works all the time, even if the garbage collector runs.
You don’t need to save a reference variable that refers to the
JFrameobject (unless you want to use it later). All you need is to call the constructorJFrame(), and the window will be constructed. Hence, in all cases, it should work without any problem.