Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Diference between close() and dispose()

952782Jul 30 2012 — edited Aug 2 2012
in Java Swings we had two methods to close a JFrame, i.e frame.dispose() and frame.hide() / or frame.setVisible(false).

But in FX, we have a single methos to close the stage which is : Stage.close() and it is equivalent to hide().

So does that mean, on calling stage.close(), the memory and the resources allocated to the stage remain intact and the stage is only vanished from the screen?

Does that further imply, FX doesnt have any method to comple 'dispose' of the stage as in swings?

please reply

Edited by: 949779 on Jul 30, 2012 6:17 AM

Comments

john16384
The docs donot say anything about the resource management done by Stages. Comparing it with Swing is useless since they're completely different.

The reason for dispose() in Swing was that even when your code does not refer to a JFrame anymore, there are still native resources which refer to the JFrame which will keep it from being garbage collected. Dispose() releases those resources.

In JavaFX the distinction between close and dispose is probably no longer needed because using weak refs they can track when the Stage is no longer referenced anymore and then release all resources associated with it (if it works that way at all).

So, close() would 'hide' the Stage, and when it gets garbage collected an automatic 'dispose' occurs. If Stages needed any further special treatment I would expect a mention in the docs.
shakir.gusaroff
Hi. The JavaFX lifecycle is different than the Swing lifecycle.
In JavaFX when you close the last window or the application calls Platform.exit() the JavaFX runtime calls Application.stop()
to prepare for application exit and destroys resources.
For more info take a look at: http://docs.oracle.com/javafx/2/api/javafx/application/Application.html
952782
Thanks guys.. you both are right! well atleasat!
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 30 2012
Added on Jul 30 2012
3 comments
7,394 views