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) {
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;
}
}
More information about the openjfx-dev
mailing list