import javafx.application.Application; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.ScrollPane; 
import javafx.scene.control.TableColumn; 
import javafx.scene.control.TableView; 
import javafx.scene.layout.StackPane; 
import javafx.scene.layout.VBox; 
import javafx.stage.Stage; 

public class LeakProducer extends Application { 

   @Override 
   public void start(Stage primaryStage) { 

      final StackPane root = new StackPane(); 
      final VBox myBox = new VBox(); 

      Button tabBarBtn = new Button(); 
      tabBarBtn.setText("TableView"); 
      tabBarBtn.setOnAction(x -> { 

         if (myBox.getChildren().size() > 1) { 
            myBox.getChildren().remove(1); 
            System.gc(); 
            System.runFinalization(); 
         } else { 
            ScrollPane sp = new ScrollPane(); 
            sp.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); 
            sp.setVbarPolicy(ScrollPane.ScrollBarPolicy.ALWAYS); 

            TableView<TableColumn> table = new TableView<>(); 
            TableColumn firstNameCol = new TableColumn("First Name"); 
            TableColumn lastNameCol = new TableColumn("Last Name"); 
            TableColumn emailCol = new TableColumn("Email"); 

            table.getColumns().addAll(firstNameCol, lastNameCol, emailCol); 

            sp.setContent(table); 
            myBox.getChildren().add(sp); 
         } 
      }); 

      Scene scene = new Scene(root, 300, 250); 

      myBox.getChildren().add(tabBarBtn); 

      root.getChildren().addAll(myBox); 
      primaryStage.setScene(scene); 
      primaryStage.show(); 
   } 


   public static void main(String[] args) { 
      System.out.println("==============================="); 
      System.out.println("Java Version: " + System.getProperty("java.version")); 
      System.out.println("==============================="); 
      launch(args); 
   } 
} 