I am wondering about a piece of code:
public void render()
{
BufferStrategy bs = getBufferStrategy();
if(bs == null)
{
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.dispose();
bs.show();
}
Render is in a Game Loop.
In the book I am reading, it says I need to call dispose here. I don't really understand why. Isn't it overwriting g every time render loops anyway.
According to the JavaDoc is should be done for performance reasons. It will be disposed by itself through the garbage collector if all referances are released.
You're asking:
Well, in your case you create a new
Graphics
object every time you inquire for a graphics context. Therefore, the dispose should be called as if it is only called once, since every instance is an isolated case.