1

After wondering whether disposing my frame would return a null (if checked) I went ahead and tested it out. I've searched on dispose() but most of the articles I read just state when to use it, not what it actually does. I tried out the sample code, maybe my code is simply incorrect but if it's not. What does dispose() actually do inside the JVM?

If someone does find a link related to this, please post it so I can remove this question

Juxhin
  • 5,068
  • 8
  • 29
  • 55

2 Answers2

1

1) No method ever can set your variable to null. Never ever. It may change an internal state so any future call may throw an error (e.g. with a Socket), but the variable itself won't be changed. You need to do this explicitly yourself.

2) Read the javadocs :)

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. [...]

ZeissS
  • 11,867
  • 4
  • 35
  • 50
1

Objects can change their state. However, they cannot willy-nilly change any state in the entire collection of other objects.

So, if you call any method on an object, it will not have a direct impact on any reference to that object from any possible other object.

In your case, dispose() is releasing the in-object references to the wrapped OS level components, not removing the Java object from the environment (and clearing out its references).

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138