Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a game using Java and OpenGL using the JOGL bindings. I noticed that my game doesn't terminate properly when closing the window even though I've set the closing operation of the JFrame to EXIT_ON_CLOSE. I couldn't track down where the problem was so I've made a small reproduction case. Note that on some computers the program terminates normally when closing the window but on other computers (notably my own) something in the JVM keeps lingering, this causes the JFrame to never be disposed and the application to never exit. I haven't found something in common between the computers that had difficulty terminating. All computers had Windows 7, Java 7 and the same version of JOGL and some terminated normally while others had this problem.

The test case is as follows:

public class App extends JFrame implements GLEventListener
    private GLCanvas canvas; 

    public void display(GLAutoDrawable drawable) 
        GL3 gl = drawable.getGL().getGL3();

        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


    // The overrides for dispose (the OpenGL one), init and reshape are empty

    public App(String title, boolean full_screen, int width, int height)
        //snipped setting the width and height of the JFRAME

        GLProfile profile = GLProfile.get(GLProfile.GL3);
        GLCapabilities capabilities = new GLCapabilities(profile);

        canvas = new GLCanvas(capabilities);
        canvas.setSize(getWidth(), getHeight());


        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //!!!


    public void dispose()
        System.out.println("HELP"); // 

    public static void main( String[] args )
        new App("gltut 01", false, 1280, 720);

As you can see this doesn't do much more than adding a GLCanvas to the frame and registering the main class as the GLEventListener.

So what keeps lingering? I'm not sure. I've made some screenshots.

The application running normally.

While Running

The application after the JFrame is closed, note that the JVM still hasn't exited or printed a return code.


The application after it was force closed.

Force closed

Note the return code -1, so it wasnt just the JVM standing by or something the application really hadn't exited yet.

So what is keeping the application in Limbo? Might it be the circular reference between the GLCanvas and the JFrame? I thought the GC could figure that out. If so how should I deal with that when I want to exit? Is there any other clean-up required when using JOGL? I've tried searching but it doesn't seem to be necessary.

Edit, to clarify: there are 2 dispose functions dispose(GLAutoDrawable arg) which is a member of GLEventListener and dispose() which is a member of JFrame. The first one is called correctly (but I wouldn't know what to there, destroying the GLAutoDrawable or the GLCanvas gives an infinite exception loop) the second one is never called.

Edit 2, October 30th I've tried the following suggestions as per the comments:

  • Setting the default close operation to DISPOSE_ON_CLOSE doesn't have any effect

  • Adding an adapter for the windowClosing works and it is properly called but calling System.exit(0); there doesn't stop the program, something is left behind.

  • Adding a shutdown hook works and shutdown hooks are correctly processed however even adding exit there doesn't help.

share|improve this question

closed as off-topic by Josh Petrie Jan 4 '14 at 17:25

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the question.

terminates fine for me on win 7 x64 – Ray Tayek Oct 24 '12 at 11:43
Exactly what makes this problem so hard. I'm curious what more I can do to dispose/clean JOGL before exiting. – Roy T. Oct 24 '12 at 15:34
And if you remove the dispose() override? – Torious Oct 28 '12 at 21:43
I can't, it's an interface I override there not an (abstract) class. So I have to override it. – Roy T. Oct 29 '12 at 8:07
public void dispose() is a method in java.awt.Window. You should not override it. Is the provided code up-to-date? – msell Oct 29 '12 at 9:51

Browse other questions tagged or ask your own question.