0 Replies Latest reply: Feb 15, 2013 1:41 AM by 989211 RSS

    50 MB increase in memory consumption on displaying an Image

    989211
      I have a JavaFX application (Swing users input might also help) which is Image gallery basically. It watches a folder, and as soon as any Image is added, the Image is displayed on the screen.

      Sooner as more Images got added, the application memory consumption only grew bigger. On profiling, I have observed that on adding an Image (size 1.3 MB), memory consumption increased by about 50 MB. The class that holds Image is a simple ImageView that holds an Image. Does any one have similar experiences? The behavior is same on Windows & Mac

      PS: I know any code here will help, but there is nothing much to be shown. As I said there is a List of ImageView which holds Image. List of ImageView is binded to another List say l1. On detecting an Image, image is added to l1 and so is added to the actual list which is displayed on screen

      EDIT:

      This is a sample program. It loads 6 Images and displays them. Each Image in my case was of size 2.3 MB. But I have observed, that it consumes 10 MB approx for each Image and 65 MB overall.



      /*
      * To change this template, choose Tools | Templates
      * and open the template in the editor.
      */
      package side;

      import java.io.File;
      import java.io.FileInputStream;
      import java.io.InputStream;
      import javafx.application.Application;
      import javafx.geometry.Orientation;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.ScrollBar;
      import javafx.scene.image.Image;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      /**
      *
      * @author Jatin
      */
      public class Test extends Application {

      public static void main(String... args) {
      launch(args);
      }

      @Override
      public void start(Stage primaryStage) throws Exception {
      ScrollBar bar = new ScrollBar();
      bar.setOrientation(Orientation.VERTICAL);


      final VBox box = new VBox();
      Group root = new Group();
      root.getChildren().addAll(box, bar);
      Scene scene = new Scene(root);
      primaryStage.setScene(scene);
      primaryStage.setTitle("Layout Sample");
      primaryStage.show();


      for (int ik = 0; ik < 6; ik++) {
      System.out.println("1");
      ImageView i = new ImageView();
      InputStream is = new FileInputStream(new File("C:\\Users\\Jatin\\Documents\\BarcodeNew\\w.png"));
      Image im = new Image(is);
      i.setImage(im);
      box.getChildren().add(i);
      is.close();
      }

      //r.close();


      }
      }

      Edited by: 986208 on Feb 14, 2013 11:38 PM