Material setting images cost too much memory also cause application slow

XMLWordPrintable

    • Type: Bug
    • Resolution: Cannot Reproduce
    • Priority: P4
    • 9
    • Affects Version/s: 8u25
    • Component/s: javafx
    • Environment:

      Windows 7 Professional

      I write an app need to load lots of images to preform 3D view.

      When I load a lot of different images into the app, the app become really slow. After I profile this app, I find out when I add a 7M image into my app, the Total memory cost will increase about 100M.

      So here I changed the simple code from ORACLE to do some test : http://docs.oracle.com/javase/8/javafx/graphics-tutorial/sampleapp3d.htm.

      My changed code is in MoleculeSampleApp.java:
          ---------------------------------------------------------------------------------------------
      private void buildMolecule() throws FileNotFoundException, IOException {
             //------------------------------------ I load three big images here------------------
              String path1 = "large1.jpg";
              String path2 = "large2.jpg";
              String path3 = "large3.jpg";
              InputStream stream1 = new FileInputStream(path1);
              Image image1 = new Image(stream1);
              stream1.close();
              InputStream stream2 = new FileInputStream(path2);
              Image image2 = new Image(stream2);
              stream2.close();
              InputStream stream3 = new FileInputStream(path3);
              Image image3 = new Image(stream3);
              stream3.close();
              //---------------------------------------------------------------------------
              
             final PhongMaterial redMaterial = new PhongMaterial();
              redMaterial.setDiffuseColor(Color.DARKRED);
              redMaterial.setSpecularColor(Color.RED);
              // Add image1 to redMeterial
              redMaterial.setSpecularMap(image1);
       

              final PhongMaterial whiteMaterial = new PhongMaterial();
              whiteMaterial.setDiffuseColor(Color.WHITE);
              whiteMaterial.setSpecularColor(Color.LIGHTBLUE);
              //Add image2 to whiteMaterial
              whiteMaterial.setSpecularMap(image2);
              
              final PhongMaterial greyMaterial = new PhongMaterial();
              greyMaterial.setDiffuseColor(Color.DARKGREY);
              greyMaterial.setSpecularColor(Color.GREY);
              //Add image3 to greyMaterial
              greyMaterial.setSpecularMap(image3);
              ...........................

      -----------------------------------------------------------------------------------

      Each of the images is about 14M.

      Then I begin to profile the code with the profile tool in NetBeans.

      First
      I comment these three lines and profile the code:
      redMaterial.setSpecularMap(image1);
      whiteMaterial.setSpecularMap(image2);
      greyMaterial.setSpecularMap(image3);

      The Total Memroy cost is 49M and Used Memroy is 8M.
      **********************************************************************

      Second
      I comment two lines and profile the code :
      whiteMaterial.setSpecularMap(image2);
      greyMaterial.setSpecularMap(image3);

      image1 is 13.2M

      The Total Memroy cost is 283M and Used Memroy is 236M.
      **********************************************************************

      Third
      I comment one line and profile the code:
      greyMaterial.setSpecularMap(image3);

      image1 and image2 together is 26.9M

      The Total Memroy cost is 550M and Used Memroy is 502M.

      **********************************************************************

      Fourth
      I profile the code and three images are all added to each node.

      The three images is 44.5M

      The Total Memroy cost is 696 and Used Memroy is 650M.

      *********************************************************************
      Also after adding the images, the camera moving and zooming will not work as smoothly as the one without set images(app slow).

      I don't know whether this is normal for the 3D things. But adding images to JAVAFX codes will cost too much space and slow down the application.

            Assignee:
            Elina Kleyman (Inactive)
            Reporter:
            J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: