湖南企业做网站,中国建筑模板十大名牌,做淘宝客网站要不要备案,wordpress 修改功能javafx 内存占用在我的一个项目中#xff0c;最近几天我在与内存泄漏作斗争#xff08;是……“耦合”#xff09;#xff0c;我得出的结论是可能存在与触摸/滚动手势有关的问题。 在下面的示例中#xff0c;我有两个按钮。 第一个创建具有一千行的列表视图#xff0c;第… javafx 内存占用 在我的一个项目中最近几天我在与内存泄漏作斗争是……“耦合”我得出的结论是可能存在与触摸/滚动手势有关的问题。 在下面的示例中我有两个按钮。 第一个创建具有一千行的列表视图第二个将其删除。 我做了以下观察 当我单击“创建”并立即单击“销毁”时所有内容将被垃圾收集。 当我单击“创建”并使用滚动条向下滚动然后单击“销毁”时一切将被垃圾收集。 当我单击“创建”然后使用手势向下滚动使用Mac Magic Mouse时垃圾收集失败。 我使用了JDK附带的jvisualvm 并使用“ Sampler”选项卡查看堆空间。 我筛选了“ TestItem”类然后看到在按下“创建”按钮后那些项始终仍在内存中为最后一个ListView创建的那些项。 当我转储堆并使用“ Eclipse Memory Analyzer”对其进行分析时我可以看到很可能是ScrollGesture保留了对列表视图/数据的引用。 有人可以确认吗 这是一个已知的错误 我在Java错误数据库中找不到与此问题相关的任何内容。 import java.util.ArrayList;
import java.util.List;import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;public class MemoryLeakListViewApp extends Application {Overridepublic void start(Stage primaryStage) throws Exception {BorderPane pane new BorderPane();Scene scene new Scene(pane);Button createButton new Button(Create);createButton.setOnAction(evt - {ListView listView new ListView();List children new ArrayList();for (int i 0; i 1000; i) {children.add(new TestItem(Row i));}listView.getItems().setAll(children);pane.setCenter(listView); });Button deleteButton new Button(Destroy); deleteButton.setOnAction(evt - {pane.setCenter(null);});HBox box new HBox();box.getChildren().addAll(createButton, deleteButton);pane.setTop(box);primaryStage.setScene(scene);primaryStage.setWidth(800);primaryStage.setHeight(800);primaryStage.show();}static class TestItem {private String name;public TestItem(String name) {this.name name;}Overridepublic String toString() {return name;}}public static void main(String[] args) {launch(args);}
}翻译自: https://www.javacodegeeks.com/2016/02/javafx-touchgesture-memory-leak.htmljavafx 内存占用