IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Java heap space avec xms et xmx


Sujet :

Java

  1. #1
    Membre actif

    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    339
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 339
    Points : 279
    Points
    279
    Par défaut Java heap space avec xms et xmx
    Salut à tous,

    Je développe actuellement une application capable de manipuler des cartes géographiques. Actuellement, je suis sur un plus petit module qui permet d'adapter n'importe quelle carte scannée sur une carte existante (genre un cadastre).

    A chaque fois que je démarre mon application, j'ai droit à un "outofmemoryerror" alors que j'ai dimensionnée ma mémoire (avec xms et xmx) de manière largement suffisante. Voici le log pour mieux comprendre :
    cd Maps/Mapsimage && java -Xms64M -Xmx128M -jar Cusimage.jar
    init = 67108864(65536K) used = 2829704(2763K) committed = 66650112(65088K) max = 133234688(130112K)
    init = 67108864(65536K) used = 2875144(2807K) committed = 66650112(65088K) max = 133234688(130112K)
    init = 67108864(65536K) used = 8496784(8297K) committed = 66650112(65088K) max = 133234688(130112K)
    Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
    at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
    at java.awt.image.Raster.createPackedRaster(Raster.java:458)
    at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
    at java.awt.image.BufferedImage.<init>(BufferedImage.java:323)
    at Img_addMap.Draw(Img_addMap.java:42)
    at MapsPanel.paintComponent(MapsPanel.java:66)
    at javax.swing.JComponent.paint(JComponent.java:1006)
    at javax.swing.JComponent.paintChildren(JComponent.java:843)
    at javax.swing.JComponent.paint(JComponent.java:1015)
    at javax.swing.JComponent.paintChildren(JComponent.java:843)
    at javax.swing.JComponent.paint(JComponent.java:1015)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:559)
    at javax.swing.JComponent.paintChildren(JComponent.java:843)
    at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4979)
    at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)
    at javax.swing.JComponent.paint(JComponent.java:996)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
    at java.awt.Container.paint(Container.java:1709)
    at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
    at sun.awt.X11.XRepaintArea.paintComponent(XRepaintArea.java:56)
    at sun.awt.RepaintArea.paint(RepaintArea.java:224)
    at sun.awt.X11.XComponentPeer.handleEvent(XComponentPeer.java:645)
    at java.awt.Component.dispatchEventImpl(Component.java:4060)
    at java.awt.Container.dispatchEventImpl(Container.java:2024)
    at java.awt.Window.dispatchEventImpl(Window.java:1791)
    at java.awt.Component.dispatchEvent(Component.java:3819)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    init = 67108864(65536K) used = 7802168(7619K) committed = 133234688(130112K) max = 133234688(130112K)
    init = 67108864(65536K) used = 11459048(11190K) committed = 133234688(130112K) max = 133234688(130112K)
    L'affichage de la mémoire est demandé à chaque fois que la carte est redessinnée.

    Comment je peux avoir un problème de mémoire insuffisante alors que ma mémoire est initialisée et maximisable à des valeurs bien au-delà de ce qui est nécessaire ?

    Merci d'avance

  2. #2
    Membre expérimenté
    Avatar de Patriarch24
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2003
    Messages
    1 047
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2003
    Messages : 1 047
    Points : 1 640
    Points
    1 640
    Par défaut
    As-tu essayé avec 256, 512... ?

  3. #3
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Points : 7 163
    Points
    7 163
    Par défaut
    Quelle est la taille des différents BufferedImage lors du crash ?
    Par quels calculs/raisonnements arrives-tu à la conclusion que tu as correctement dimensionné la mémoire allouée a ton application ?

  4. #4
    Membre actif

    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    339
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 339
    Points : 279
    Points
    279
    Par défaut
    J'ai bien essayé différentes tailles mémoires(64,128,256) mais sans succès

    L'image est une bitmap de 4,2MO. Les autres données prennent au maximum 250ko en mémoire. Si je compte mon affichage en 1280*1024*32bits et que je double la taille mémoire de la bitmap, j'arrive à 10MO maxi. Le problème c'est que si je lance l'appli sans xms ni xmx, j'ai également un outofmemoryerror....

  5. #5
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Salut,


    On pourrait voir le code correspondant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    at Img_addMap.Draw(Img_addMap.java:42)
    at MapsPanel.paintComponent(MapsPanel.java:66)
    a++

  6. #6
    Membre actif

    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    339
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 339
    Points : 279
    Points
    279
    Par défaut
    Pas de problème. Pour Img_addMap.Draw :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
     public static void Draw(Graphics2D g2d) {
      int xmin = X0 - LargeX;
     
     
      int ymax = Y0 + LargeY;
      int PosVirtXMin = (xmin-MapsPanel.Xmin)/Datas.scale[MapsPanel.scale];
      int PosVirtYMin = MapsPanel.panel_height-((ymax-MapsPanel.Ymin)/Datas.scale[MapsPanel.scale]);
      int w = LargeX/Datas.scale[MapsPanel.scale];
      int h = LargeY/Datas.scale[MapsPanel.scale];
     
      BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = buf.createGraphics();
      g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER,(float)transp/255));
      g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      g.drawImage(bi, 0, 0, w, h, null);
      g.dispose();
     
      g2d.drawImage(buf,PosVirtXMin,PosVirtYMin,w,h,null);
     }
    Pour MapsPanel.paintComponent :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
     
     public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2d = (Graphics2D) g;
     
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
      g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
      g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
      g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
     
      Datas.type_displayed.clear();
      Datas.id_displayed.clear();
      Datas.nb_displayed = 0;
     
      g2d.setColor(new Color(255, 255, 255, 255));
      g2d.fillRect(0,0,panel_width,panel_height);
     
      MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
      System.out.println(memoryBean.getHeapMemoryUsage());
     
      for (int i=0; i<Datas.nb_polygon; i++) {
       ObjPolygon.Draw(g2d,i);
      }
     
      for (int i=0; i<Datas.nb_texts; i++) {
       ObjText.Draw(g2d,i);
      }
     
      for (int i=0; i<Datas.nb_img; i++) {
       Img.Draw(g2d,i);
      }
     
     
      if (Img_addMap.LargeX != 0) {
       Img_addMap.Draw(g2d);
      }
     
     }

  7. #7
    Membre actif

    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    339
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 339
    Points : 279
    Points
    279
    Par défaut
    Quelques petites précisions supplémentaires. Tout d'abord, je sais que le code n'est pas optimisé mais ça je verrais plus tard

    La ligne Img_addMap.Draw(Img_addMap.java:42) correspond à :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Il n'y a que 8 polygones vectoriels à tracer(ObjPolygon.Draw) dans l'exemple que j'ai prix, ainsi que 8 éléments textes(ObjText.Draw). Il n'y a aucune image supplémentaire(Img.Draw) à part la carte que j'essaye d'adapter "au fond cadastral"(Img_addMap.Draw).

  8. #8
    Expert éminent sénior
    Avatar de adiGuba
    Homme Profil pro
    Développeur Java/Web
    Inscrit en
    Avril 2002
    Messages
    13 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java/Web
    Secteur : Transports

    Informations forums :
    Inscription : Avril 2002
    Messages : 13 938
    Points : 23 190
    Points
    23 190
    Billets dans le blog
    1
    Par défaut
    Quels sont les valeurs de w et h :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    a++

  9. #9
    Membre actif

    Profil pro
    Inscrit en
    Décembre 2002
    Messages
    339
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2002
    Messages : 339
    Points : 279
    Points
    279
    Par défaut
    Effectivement, le problème vient bien de w et h. Dans mes tests, je sortais la valeur finale de w et h et pas les valeurs à l'initialisation comme l'image s'affichait.

    Au départ j'ai
    w = 9476
    h = 5928
    alors qu'en valeur finale j'ai :
    w = 379
    h = 237
    Du coup, l'appli a besoin d'un peu moins de 2GO pour initialiser l'image.

    Merci beaucoup du coup de main

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème mémoire Java heap space avec tableau et ArrayList
    Par phoenix420 dans le forum Collection et Stream
    Réponses: 45
    Dernier message: 22/06/2010, 10h01
  2. Problème avec le Java heap space
    Par Viscapon dans le forum JSF
    Réponses: 5
    Dernier message: 18/05/2009, 17h42
  3. [Info] Chargement image et Java heap space
    Par dazz_x dans le forum Langage
    Réponses: 9
    Dernier message: 11/09/2007, 11h51
  4. Eclipse erreur : java.lang.OutOfMemoryError: Java heap space
    Par sderecourt dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 14/04/2006, 11h28
  5. [ memoire ] Java Heap Space
    Par natha dans le forum Général Java
    Réponses: 10
    Dernier message: 23/01/2006, 11h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo