I created an example application that causes a memory leak.
The problem is that I need to βreloadβ the scene. If I have two scenes (Bar and Foo) with each button (ButtonBar and ButtonFoo), the buttons change the current scene, creating a new one. If I stay pressed ButtonBar and ButtonFoo for 5 minutes (or less), the memory consumption of this simple program gets higher and higher.
Bar.java
public class Bar implements Initializable {
@FXML
private Label label;
@FXML
private void toFoo(ActionEvent event) {
try {
Button button = (Button) event.getSource();
Parent root = FXMLLoader.load(getClass().getResource("Foo.fxml"));
Stage currentStage = (Stage) button.getScene().getWindow();
currentStage.setScene(new Scene(root));
} catch (IOException ex) {
Logger.getLogger(Bar.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void initialize(URL url, ResourceBundle rb) {
}
}
Foo.java is the same as changing fxml loading.
The fxml file contains only one button:
<Button id="buttonBar" layoutX="126" layoutY="90" text="Bar!" onAction="#toFoo" fx:id="buttonBar" />
Is there a real memory leak problem? Does anyone know another way to do this? I want this application to stay alive and constantly changing as a service. Thanks