This problem affects the internal Browser app. If you open several tabs with WebView and close them, you'll see that garbage collector could not release WebView instances. It leads to OutOfMemoryException.
Try the following automatic test with the following JVM args: -agentlib:hprof=heap=dump,format=b; and jhat shows strong references to TextField instances. Note that the problem is not reproducible if this.pane is not rendered.
public class Test extends Application implements Runnable {
public static void main(String[] args) {
launch(args);
}
private TabPane pane;
public void start(Stage stage) {
Tab[] tabs = new Tab[40];
for (int i = 0; i < tabs.length; i++) {
String content = Integer.toString(i);
tabs[i] = new Tab(content);
tabs[i].setContent(new TextField(content));
}
this.pane = new TabPane();
this.pane.getTabs().addAll(tabs);
stage.setScene(new Scene(this.pane));
stage.setVisible(true);
run();
}
public void run() {
if (0 < this.pane.getTabs().size()) {
this.pane.getTabs().remove(0);
try {
int[] array = new int[1024];
while (true) {
array = new int[array.length << 1];
}
}
catch (OutOfMemoryError error) {
System.gc();
}
Platform.runLater(this);
}
else {
Platform.exit();
}
}
}
Try the following automatic test with the following JVM args: -agentlib:hprof=heap=dump,format=b; and jhat shows strong references to TextField instances. Note that the problem is not reproducible if this.pane is not rendered.
public class Test extends Application implements Runnable {
public static void main(String[] args) {
launch(args);
}
private TabPane pane;
public void start(Stage stage) {
Tab[] tabs = new Tab[40];
for (int i = 0; i < tabs.length; i++) {
String content = Integer.toString(i);
tabs[i] = new Tab(content);
tabs[i].setContent(new TextField(content));
}
this.pane = new TabPane();
this.pane.getTabs().addAll(tabs);
stage.setScene(new Scene(this.pane));
stage.setVisible(true);
run();
}
public void run() {
if (0 < this.pane.getTabs().size()) {
this.pane.getTabs().remove(0);
try {
int[] array = new int[1024];
while (true) {
array = new int[array.length << 1];
}
}
catch (OutOfMemoryError error) {
System.gc();
}
Platform.runLater(this);
}
else {
Platform.exit();
}
}
}