Fixed stream memory leak

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2 3 years ago
parent 1d37ec04a8
commit bb52b2737d
  1. BIN
      bin/SigShare.jar
  2. BIN
      bin/screenshot.jpg
  3. BIN
      bin/screenshot_out.jpg
  4. 5
      src/sig/SigShare.java
  5. 4
      src/sig/engine/Panel.java

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 KiB

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 40 KiB

@ -130,7 +130,7 @@ public class SigShare {
while (in.available()>0) {
if (stream==null) {
//System.out.println("Stream opened.");
stream=new BufferedOutputStream(new FileOutputStream(new File("screenshot_out.jpg")));
stream=new BufferedOutputStream(new FileOutputStream(new File("screenshot_out.jpg"),true));
}
int val = in.read();
stream.write(val);
@ -141,7 +141,7 @@ public class SigShare {
dashCount=0;
}
}
if (dashCount>=10&&stream!=null) {
if (dashCount>=10) {
stream.close();
stream=null;
dashCount=0;
@ -155,6 +155,7 @@ public class SigShare {
}
}
out.writeChars("Done\r\n");
stream=new BufferedOutputStream(new FileOutputStream(new File("screenshot_out.jpg"),false));
}
}
}

@ -107,7 +107,9 @@ public class Panel extends JPanel implements Runnable {
// ask ImageProducer to update image
mImageProducer.newPixels();
// draw it on panel
g.drawImage(this.imageBuffer.getScaledInstance(getWidth(), getHeight(), Image.SCALE_FAST), 0, 0, this);
Image f = this.imageBuffer.getScaledInstance(getWidth(), getHeight(), Image.SCALE_FAST);
g.drawImage(f, 0, 0, this);
f.flush();
if (window!=null&&System.currentTimeMillis()-lastSecond>=1000) {

Loading…
Cancel
Save