LWJGL Memory leak/Function running many times

Why is something that should only run one inside the draw loop?

I looked at the LWJGL tutorials on their website and most of them do something like :


public class Game
{
       public Game()
       {
               //init
               //drawloop
       }
       public static void main(String[] args)
       {
                new Game();
       }
}

so the entire game runs in the main constructor the whole time. Im not saying this is what is happening, I haven’t seen his code either but i’m pretty sure it is.

he seems to be creating a texture every frame

Never do work in a constructor.

I personally don’t, but most people learned at least partly from LWJGL tutorials and those all do the work in the constructor. Ex: http://lwjgl.org/wiki/index.php?title=The_Quad_with_DrawArrays

I think those tutorials assume you know the basics of do’s and dont’s in programming. They are small code examples and you are supposed to pull out the information you need from them. Pretty much everyone knows not to do extensive work in constructors, especially not run entire games in them.

Another tip - the OOME is being caused by a direct buffer allocation; these live outside of the heap and are unaffected by the -Xmx parameter. The switch governing the amount of direct memory available is -XX:MaxDirectMemorySize=…

Cas :slight_smile: