Details
Description
ProgressIndicatorTest has memory leak has memory leak when it is used in separate Stage.
/*
* Created on Oct 18, 2012
*/
package mytests;
import javafx.application.*;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.stage.*;
/**
* @author mifeld
*/
public class ProgressIndicatorTest extends Application
{
@Override
public void start(final Stage stage) throws Exception
{
Button butt = new Button("Show dialog");
butt.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent arg0)
{
showDialog(stage);
}
});
Scene scene = new Scene(butt, 300, 250);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args)
{
Application.launch(args);
}
private static void initStage(Stage stage)
{
stage.centerOnScreen();
stage.initModality(Modality.APPLICATION_MODAL);
}
private static void showDialog(Stage stage)
{
Stage dialog = createDialog();
initStage(dialog);
dialog.show();
}
private static Stage createDialog()
{
final ProgressIndicator pi = new ProgressIndicator();
Button button = new Button();
button.setText("Cancel");
VBox vbox = new VBox(20);
vbox.getChildren().setAll(pi,button);
Scene scene = new Scene(vbox);
scene.setFill(Color.LIGHTGRAY);
final Stage res = new Stage(StageStyle.UTILITY);
res.setScene(scene);
button.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent avt)
{
res.close();
}
});
return res;
}
}
You can see that after Stage.close() the instance of ProgressIndicator will never garbage collected
/*
* Created on Oct 18, 2012
*/
package mytests;
import javafx.application.*;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.paint.*;
import javafx.stage.*;
/**
* @author mifeld
*/
public class ProgressIndicatorTest extends Application
{
@Override
public void start(final Stage stage) throws Exception
{
Button butt = new Button("Show dialog");
butt.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent arg0)
{
showDialog(stage);
}
});
Scene scene = new Scene(butt, 300, 250);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args)
{
Application.launch(args);
}
private static void initStage(Stage stage)
{
stage.centerOnScreen();
stage.initModality(Modality.APPLICATION_MODAL);
}
private static void showDialog(Stage stage)
{
Stage dialog = createDialog();
initStage(dialog);
dialog.show();
}
private static Stage createDialog()
{
final ProgressIndicator pi = new ProgressIndicator();
Button button = new Button();
button.setText("Cancel");
VBox vbox = new VBox(20);
vbox.getChildren().setAll(pi,button);
Scene scene = new Scene(vbox);
scene.setFill(Color.LIGHTGRAY);
final Stage res = new Stage(StageStyle.UTILITY);
res.setScene(scene);
button.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent avt)
{
res.close();
}
});
return res;
}
}
You can see that after Stage.close() the instance of ProgressIndicator will never garbage collected