JavaFX ImageView memory leak

I am working on a JavaFX image slide show application and after some time a java error without free memory error has worked. In the interface code, I have:

image = new ImageView(); Group root = new Group(image); imageScene = new Scene(root, height, width); primaryStage.setScene(imageScene); 

In the background thread, I set the image source to view the image:

 ... 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); 

Although running the application (with parameters: -XX: + UnlockExperimentalVMOptions -XX: + UseG1GC -Xmx256m), the memory allocated for the Java process always increases ...

+4
source share
1 answer

Reduce image size using the code below

 Image img = ic.getImage(); Image newimg = img.getScaledInstance(500, 700, java.awt.Image.SCALE_SMOOTH); 

I am sure that you are using the original image size in this application.

-5
source

Source: https://habr.com/ru/post/1497038/


All Articles