Reputation: 176
The value isn't necessarily null (I think?), because it is still a valid reference.
Upvotes: 2
Views: 761
Reputation: 285405
A JFrame is an object and so can never be null, while a JFrame variable can either refer to a valid JFrame object or have no reference and thus "be null". If you call dispose()
on the JFrame object the object still exists and so the variable is not null. The JFrame however has released some system resources. These resources will be gained again if the JFrame object is re-rendered.
As is often the case, the best test for a question like this is to 1) create and run test code and 2) check the API
e.g.,
JFrame frame = new JFrame("Foo");
frame.pack();
frame.setVisible(true);
// in some listener
frame.dispose(); // it's no longer visible
System.out.println("is frame null? " + (frame == null));
Per the Window API, where the dispose method is inherited from:
Releases all of the native screen resources used by this Window, its subcomponents, and all of its owned children. That is, the resources for these Components will be destroyed, any memory they consume will be returned to the OS, and they will be marked as undisplayable. The Window and its subcomponents can be made displayable again by rebuilding the native resources with a subsequent call to pack or show. The states of the recreated Window and its subcomponents will be identical to the states of these objects at the point where the Window was disposed (not accounting for additional modifications between those actions).
Upvotes: 3