I have a
bufferedImage
which is getting drawn to and then rendered to the screen every frame. The issue is that for some reason, when getting the graphics from it, it leaks some memory, usually about 0.1-0.2 mb per iteration.
here is some of the code I used:
BufferedImage bi;
bi= ImageLoader.gc.createCompatibleImage(Display.getWidth(), Display.getHeight(), Transparency.TRANSLUCENT);
bi.setAccelerationPriority(1);
public void render() {
bs = display.getCanvas().getBufferStrategy();
if(bs == null) {
display.getCanvas().createBufferStrategy(3);
return;
}
g = (Graphics2D)bs.getDrawGraphics();
g.clearRect(0, 0, Display.getWidth(), Display.getHeight());
Graphics g2 = bi.createGraphics();
g2.clearRect(0, 0, bi.getWidth(), bi.getHeight());
g2.dispose();
g.drawImage(bi, 0,0,Display.getWidth(), Display.getHeight(), null);
bs.show();
bi.flush();
g.dispose();
}
the
g
is a graphics object and
bs
is a bufferstrategy object that comes from the canvas that is made with the JFrame.
What I have tried:
I have tried disposing of the
bufferedimage's
graphics, and tried to
flush()
the image itself, but nothing seems to fix the memory leakage