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
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
What is the profiler actually pointing to as the problem? It's possible that there's a memory leak inside the
BufferedImage
class itself, in which case there's nothing you can do to fix it.