javafx 内存占用_JavaFX:TouchGesture内存泄漏?
javafx 內(nèi)存占用
在我的一個(gè)項(xiàng)目中,最近幾天我在與內(nèi)存泄漏作斗爭(是……“耦合”),我得出的結(jié)論是可能存在與觸摸/滾動(dòng)手勢有關(guān)的問題。 在下面的示例中,我有兩個(gè)按鈕。 第一個(gè)創(chuàng)建具有一千行的列表視圖,第二個(gè)將其刪除。
我做了以下觀察:
我使用了JDK附帶的jvisualvm ,并使用“ Sampler”選項(xiàng)卡查看堆空間。 我篩選了“ TestItem”類,然后看到在按下“創(chuàng)建”按鈕后,那些項(xiàng)始終仍在內(nèi)存中為最后一個(gè)ListView創(chuàng)建的那些項(xiàng)。
當(dāng)我轉(zhuǎn)儲(chǔ)堆并使用“ Eclipse Memory Analyzer”對(duì)其進(jìn)行分析時(shí),我可以看到很可能是ScrollGesture保留了對(duì)列表視圖/數(shù)據(jù)的引用。
有人可以確認(rèn)嗎? 這是一個(gè)已知的錯(cuò)誤? 我在Java錯(cuò)誤數(shù)據(jù)庫中找不到與此問題相關(guān)的任何內(nèi)容。
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.html
javafx 內(nèi)存占用
總結(jié)
以上是生活随笔為你收集整理的javafx 内存占用_JavaFX:TouchGesture内存泄漏?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 运行ddos攻击的工具(DDOS插件调用
- 下一篇: 安卓谷歌插件下载(安卓谷歌插件)