i have the following javafx code when executed with -Xmx10m jvm option, it runs to completion after clicking on the button (it adds and removes 250 TextFields 100000 times) on mac osx but it runs out of memory on windows 7.
on both platforms, java 1.7.0 u25 were used.
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class SimpleTextFieldTest extends Application {
private List<TextField> list = new ArrayList<TextField>();
private Label message = new Label();
private void init(Stage primaryStage) {
System.out.println("Start Testing");
for (int i = 0; i < 250; i++) {
TextField textField = new TextField();
textField.setPrefWidth(100);
textField.setText("hello");
list.add(textField);
}
System.out.println("end of initial textBox");
final VBox root = new VBox();
primaryStage.setScene(new Scene(root, 200, 200));
Button button1 = new Button();
button1.setText("Start");
button1.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent arg0) {
try{
for (int i = 0; i < 100000; i++) {
for(TextField text : list){
root.getChildren().add(text);
}
root.getChildren().removeAll(list);
}
}catch(Exception ex){
ex.printStackTrace();
}
System.out.println("end of Test");
}
});
root.getChildren().add(button1);
root.getChildren().add(message);
}
@Override
public void start(Stage primaryStage) throws Exception {
init(primaryStage);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}