-
Bug
-
Resolution: Fixed
-
P2
-
8u321, jfx17, jfx18
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8277142 | jfx17.0.2 | Kevin Rushforth | P2 | Resolved | Fixed | |
JDK-8279786 | 8u331 | Kevin Rushforth | P2 | Closed | Fixed | b04 |
Windows 10 1909 64bit
OpenJDK 17 (build 17+35-2724)
A DESCRIPTION OF THE PROBLEM :
If there are MenuItems in the Stage, after closing the Stage, the MenuItems won't get garbage collected, and thus also leaking its listeners and other related objects. It only happens on JFX 17, on JFX 16 the memory leak won't happen. Might be related with https://github.com/openjdk/jfx/pull/429.
REGRESSION : Last worked in version openjfx16
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Place a MenuItem in a Stage and launch this Stage, then launch a new Stage and close previous Stage, the MenuItem in the previous Stage won't get garbage collected.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The MenuItem in the closed Stage get garbage collected.
ACTUAL -
The MenuItem in the closed Stage won't be garbage collected.
---------- BEGIN SOURCE ----------
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
public class JavaApp extends Application {
private static final ArrayList<WeakReference<MenuItem>> uncollectedMenuItems = new ArrayList<>();
private static void clearNullMenuItems() {
uncollectedMenuItems.removeIf(ref -> ref.get() == null);
}
private static void launchNewStage(Stage stage) {
MenuItem menuItem = new MenuItem("Restart Stage");
menuItem.setOnAction(actionEvent -> {
launchNewStage(new Stage());
stage.close();
});
uncollectedMenuItems.add(new WeakReference<>(menuItem));
MenuBar menuBar = new MenuBar(new Menu("MENU", null, menuItem));
Button button = new Button("Call GC and Print MenuItems");
button.setOnAction(actionEvent -> {
System.gc();
clearNullMenuItems();
System.out.println(Arrays.toString(uncollectedMenuItems.toArray()));
});
StackPane root = new StackPane(menuBar, button);
StackPane.setAlignment(menuBar, Pos.TOP_CENTER);
stage.setTitle("JFX-Test");
stage.setMinWidth(400.0);
stage.setMinHeight(300.0);
stage.setScene(new Scene(root));
stage.show();
}
@Override
public void start(Stage primaryStage) {
launchNewStage(primaryStage);
}
public static void main(String[] args) {
launch();
}
}
---------- END SOURCE ----------
FREQUENCY : always
- backported by
-
JDK-8277142 Additional Memory Leak in ControlAcceleratorSupport
- Resolved
-
JDK-8279786 Additional Memory Leak in ControlAcceleratorSupport
- Closed
- duplicates
-
JDK-8274023 Memory Leak in ControlAcceleratorSupport (JFX 17)
- Closed
-
JDK-8276917 Memory Leak caused by MenuBarButton in ControlAcceleratorSupport
- Closed
- is blocked by
-
JDK-8244075 Accelerator of ContextMenu's MenuItem is not removed when ContextMenu is removed from Scene
- Resolved
- relates to
-
JDK-8208088 Memory Leak in ControlAcceleratorSupport
- Resolved
-
JDK-8283449 TabPane/Tab memory leak
- Open
- links to
-
Commit openjdk/jfx17u/e3b061c9
-
Commit openjdk/jfx/0d5b8f8b
-
Review openjdk/jfx17u/21
-
Review openjdk/jfx/659