Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaFX - Loading images and memory problems
    primarykey
    data
    text
    <p>I've got a problem with loading images into my application. I'm trying to make a simple image browser. On the left I've got a list of folders. After clicking on folder's name on the list images should appear on the right(flow pane). Every image is in a HBox with a border. But I'm getting error like this quickly:</p> <pre><code>java.lang.outofmemoryerror java heap space </code></pre> <p>I looked on task manager - if I load only 6 photos the app takes 500mb of memory! And another thing - if I change folder on the list the memory remains taken. While choosing another folder I'm creating new flowPane</p> <pre><code>flowPane = new FlowPane(); </code></pre> <p>So the old one with all the ImageViews should be deleted by the garbage collector, right?</p> <p>How can I manage images in my app effectively?</p> <pre><code> for(int i = 0 ; i &lt; zdjecia.length; i++){ ImageView iv2 = new ImageView(); Image image = new Image("file:"+zdjecia[i].getAbsolutePath()); iv2.setImage(image); if( image.getHeight() &gt; image.getWidth()){ iv2.fitHeightProperty().bind(szerokoscZdjecia.multiply(0.8).subtract(6)); }else iv2.fitWidthProperty().bind(szerokoscZdjecia.subtract(6)); iv2.setPreserveRatio(true); iv2.setSmooth(true); iv2.setCache(false); String styl = "-fx-border-color: #b2b3b3;" + "-fx-border-width: 2;"; HBox boxNaFotke = new HBox(); boxNaFotke.prefWidthProperty().bind(szerokoscZdjecia); boxNaFotke.prefHeightProperty().bind(szerokoscZdjecia.multiply(0.8)); boxNaFotke.setAlignment(Pos.CENTER); boxNaFotke.setStyle(styl); boxNaFotke.getChildren().add(iv2); fotki.add(boxNaFotke); flowPane.getChildren().add(boxNaFotke); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload