import javafx.application.Application; 
import javafx.application.Platform; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.ChoiceBox; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

//Start the test application with the following JVM option. -Xmx64 
public class ChoiceBoxChangeLeakTest extends Application { 

private int time = 0; 
private ChoiceBox<String> choiceBox; 
private Button changeButton; 
@Override 
public void start(Stage stage) throws Exception { 
choiceBox = new ChoiceBox<>(); 
choiceBox.setPrefWidth(200); 
changeButton = new Button("Change item"); 
changeButton.setPrefWidth(200); 

changeItems(); 
changeButton.setOnAction(event -> changeItems()); 

Scene scene = new Scene(new VBox(choiceBox, changeButton), 400, 400); 
stage.setScene(scene); 
stage.show(); 

Platform.runLater(()->{ 
//In order to reproduce the memory leak, it is necessary to display the pop-up menu at least once. 
choiceBox.show(); 
}); 
} 

private void changeItems(){ 
time++; 
changeButton.setText("Change item:"+time); 
choiceBox.getItems().clear(); 
for (int i = 0; i < 20; i++) { 
choiceBox.getItems().add("Time: " + time +", item:"+i); 
} 
} 

public static void main(String[] args) { 
launch(args); 
} 


} 