[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-openjfx-dev
Subject:    Possible bug on linux + gnome (ubuntu 18.04)
From:       Thiago Milczarek Sayao <thiago.sayao () clamed ! com ! br>
Date:       2019-06-19 12:26:06
Message-ID: CP2P15201MB2228315A16B56FAE17F290AEDEE50 () CP2P15201MB2228 ! LAMP152 ! PROD ! OUTLOOK ! COM
[Download RAW message or body]

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) { 
        launch(args); 
    } 
     
    @Override 
    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)); 
            ownerStage.show(); 
            
            Stage s = createStage(ownerStage);
            s.show();
            
            Stage s2 = createStage(s);
            s2.show();
            
            Stage s3 = createStage(s2);
            s3.show();
        });
        
        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));
        stage.show(); 
    }
    
    private Stage createStage(Stage owner) {
        Stage subStage = new Stage();
        subStage.setTitle("Sub Stage");
        subStage.initOwner(owner);
        StackPane subStackPane = new StackPane();
        subStackPane.setPrefSize(200, 200);
        Label label = new Label("Close my owner to cause memory leak");
        subStackPane.getChildren().add(label);
        subStage.setScene(new Scene(subStackPane));
    
        stages.add(new WeakReference<>(subStage));
    
        return subStage;
    }
} =


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic