title: java 'Robot' class memory leak
body: <p>I making share screen program.(client)</p>
  <p>Sadly, I found out that a memory leak was happening.</p>
  <p>To check for memory leaks, I've simplified it to:</p>
  <pre><code>import java.awt.*;
  import java.awt.image.BufferedImage;
  
  public class Sharescreen {
      public Sharescreen() {
          try {
              Robot robot = new Robot();
              Rectangle winSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
  
              while (true) {
                  BufferedImage image = robot.createScreenCapture(winSize);
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
      public static void main(String[] argv) {
          new Sharescreen();
      }
  }
  </code></pre>
  <p>Run :</p>
  <blockquote>
  <p>java -Xms50m -Xmx100m -jar &quot;Share screen.jar&quot;</p>
  </blockquote>
  <p>BUT!! 10 minutes after run the program,</p>
  <p>Memory useage:
  <a href="https://i.stack.imgur.com/Xk2wc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xk2wc.png" alt="enter image description here" /></a></p>
  <p>There must be a problem at the 'Robot' class!!!</p>
  <p>how can i fix it???</p>
  <p>java(jdk) version : openjdk 11.0</p>