Skip to content

Commit c3aad63

Browse files
committed
减少对插件对象的引用
1 parent 110f3d4 commit c3aad63

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/main/java/com/xwintop/xJavaFxTool/plugin/PluginLoader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,19 @@ public static Tab loadIsolatedPluginAsTab(PluginJarInfo plugin, TabPane tabPane)
103103

104104
Node root = generatingCodeFXMLLoader.load();
105105
Object controller = generatingCodeFXMLLoader.getController();
106+
WeakReference<Object> controllerRef = new WeakReference<>(controller);
106107

107108
tab.setContent(root);
108109
tabPane.getTabs().add(tab);
109110
tabPane.getSelectionModel().select(tab);
110111

111112
tab.setOnCloseRequest(
112113
event -> {
113-
JavaFxViewUtil.setControllerOnCloseRequest(controller, event);
114+
Object ctrl = controllerRef.get();
115+
if (ctrl != null) {
116+
JavaFxViewUtil.setControllerOnCloseRequest(ctrl, event);
117+
}
118+
114119
PluginContainer container = containerRef.get();
115120
if (container != null) {
116121
log.info("插件关闭:" + container.getPluginJarInfo().getName());

0 commit comments

Comments
 (0)