I created a sample application that provokes a memory leak.
The problem is that I need to "reload" scenes. If I have two scenes (Bar and Foo) with one button each (ButtonBar and ButtonFoo), the buttons changes the current scene creating a new one. If I stay clicking ButtonBar and ButtonFoo for 5 minutes (or less), the memory consumption of that 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) {
// TODO
}
}
The Foo.java is the same changing de fxml loading.
The fxml 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 knows another way to do this? I want that this app stay alive and doing changes forever, like a service. Thanks
I'm with a similar problem.
When i move the mouse on scene. The memory usage increases and never down.
I believe this is associated with mouse events.
Good Luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With