Possible bug on linux + gnome (ubuntu 18.04)

Thiago Milczarek Sayao thiago.sayao at clamed.com.br
Wed Jun 19 12:26:06 UTC 2019

Could anyone confirm this?

Run the sample below, click the "Run" button and then close the "Owner Stage".

On my machine, gnome shell crashes, sometimes X crashes.

import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class InitOwnerMemoryLeak extends Application {
    private static final List<WeakReference<Stage>> stages = Collections.synchronizedList(new ArrayList<>());

    public static void main(String[] args) { 
    public void start(Stage stage) {
        HBox hbox = new HBox();
        Button button = new Button("Run"); 
        button.setOnAction(event -> {
            Stage ownerStage = new Stage(); 
            ownerStage.setTitle("Owner Stage");
            stages.add(new WeakReference<>(ownerStage));
            StackPane ownerStackPane = new StackPane(); 
            ownerStackPane.setPrefSize(400, 400); 
            ownerStage.setScene(new Scene(ownerStackPane)); 
            Stage s = createStage(ownerStage);
            Stage s2 = createStage(s);
            Stage s3 = createStage(s2);
        Button forceGc = new Button("Run GC");
        forceGc.setOnAction(e -> System.gc());
        Button stageCount = new Button("Print Stages");
        stageCount.setOnAction(e -> {
            System.out.println("Stages: ");
            for(WeakReference<Stage> stageWeakReference : stages) {
                Stage s = stageWeakReference.get();
                if(s != null) {
                    System.out.println("Stage: "+s.getTitle());
        hbox.getChildren().addAll(button, forceGc, stageCount);
        stage.setScene(new Scene(hbox));
    private Stage createStage(Stage owner) {
        Stage subStage = new Stage();
        subStage.setTitle("Sub Stage");
        StackPane subStackPane = new StackPane();
        subStackPane.setPrefSize(200, 200);
        Label label = new Label("Close my owner to cause memory leak");
        subStage.setScene(new Scene(subStackPane));
        stages.add(new WeakReference<>(subStage));
        return subStage;

More information about the openjfx-dev mailing list