getScreenCoordinates(...) memory leak

I had to fix the getScreenCoordinates(…) method in LWJGLDisplaySystem to avoid allocation of int- and float-buffers each time it was called. It quite messed up memory when using LensFlare (which calls it very often), the VM even crashed after some time (the memory apparently could not be reclaimed).

I simply added 3 fields for the buffers and rewinded them in the method instead of creating them:


    private FloatBuffer tmp_getScreenCoords_mvBuffer = BufferUtils.createFloatBuffer(16);
    private FloatBuffer tmp_getScreenCoords_prBuffer = BufferUtils.createFloatBuffer(16);
    private IntBuffer tmp_getScreenCoords_vpBuffer = BufferUtils.createIntBuffer(16);

    /**
     * <code>getScreenCoordinates</code> translate world to screen coordinates.
     * Written by Marius, rewritten for LWJGL .9 by Joshua Slack.
     *
     * @param worldPosition the world position to translate.
     * @return the screen position.
     */
    public Vector3f getScreenCoordinates(Vector3f worldPosition, Vector3f store) {
        if (store == null) store = new Vector3f();

        // Modelview matrix
       tmp_getScreenCoords_mvBuffer.rewind();
       tmp_getScreenCoords_prBuffer.rewind();
       tmp_getScreenCoords_vpBuffer.rewind();
       GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, tmp_getScreenCoords_mvBuffer);
        float mvArray[][] = new float[4][4];
        for (int x = 0; x < 4; x++)
            for (int y = 0; y < 4; y++)
                mvArray[x][y] = tmp_getScreenCoords_mvBuffer.get();

        // Projection_matrix
       GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, tmp_getScreenCoords_prBuffer);
        float prArray[][] = new float[4][4];
        for (int x = 0; x < 4; x++)
            for (int y = 0; y < 4; y++)
                prArray[x][y] = tmp_getScreenCoords_prBuffer.get();

        // Viewport matrix
       GL11.glGetInteger(GL11.GL_VIEWPORT, tmp_getScreenCoords_vpBuffer);
        int[] vpArray = new int[tmp_getScreenCoords_vpBuffer.capacity()];
        for (int i = 0; i < vpArray.length; i++) {
            vpArray[i] = tmp_getScreenCoords_vpBuffer.get();
        }

        float[] result = new float[4];

        GLU.gluProject(worldPosition.x, worldPosition.y, worldPosition.z,
                mvArray, prArray, vpArray, result);

        return store.set(result[0], result[1], result[2]);
    }