[英]JavaFX ImageView memory leak
I work on image slide show application on JavaFX and after a while of working java crash with no free memory error. 我在JavaFX上的图像幻灯片应用程序上工作,经过一段时间的Java崩溃,没有可用内存错误。 In interface code I have: 在接口代码中,我有:
image = new ImageView();
Group root = new Group(image);
imageScene = new Scene(root, height, width);
primaryStage.setScene(imageScene);
In background thread I set image source for image view: 在后台线程中,我为图像视图设置了图像源:
...
Map<String, Image> imagesMap = new HashMap<>();
...
// Slide thread
if (!imagesMap.containsKey(item.File)) {
Image image = new Image(item.File);
imagesMap.put(item.File, image);
}
Image i = imagesMap.get(item.File);
image.setImage(i);
While app run(with params: -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -Xmx256m) memory allocated to java process always is increasing... 当应用运行(带有参数:-XX:+ UnlockExperimentalVMOptions -XX:+ UseG1GC -Xmx256m)时,分配给Java进程的内存总是在增加...
Reduce the image size using the below code 使用以下代码缩小图像尺寸
Image img = ic.getImage();
Image newimg = img.getScaledInstance(500, 700, java.awt.Image.SCALE_SMOOTH);
I am sure you are using the original image size in this app. 我确定您在此应用中使用的是原始图像尺寸。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.