Memory leak on shader delete and create

Dear Experts,
Please help to solve a problem observed in GLSL shader.
Memory leak identified when a shader program delete and create it again.
I’m developing an application which uses GLSL shader program with texture operations.
This application uses different shader programs at different time.
When create and delete a shader program I got a memory leak.

Here is the normal call sequence without memory leak.

Initialize() // This function called once at startup of application.
{
// Create Shader program
// Set parameters to shader.
}

Render() // This function called during each frame render.
{
// Enable shader.
// Render.
// Disable Shader.
}

Release()// This function called once at exit of application.
{
// Delete Shader program
}

But When I change shader program creation to Render(), I got memory leak.

Initialize() // This function called once at startup of application.
{
// Nothing to do.
}

Render() // This function called during each frame render.
{
// Create Shader program
// Set parameters to shader.

// Enable shader.
// Render.
// Disable Shader.
// Delete Shader program

}

Release()// This function called once at exit of application.
{
// Nothing to do.
}

Is there any delete[DestroyShader or DeleteShader] call missing in my code?

Please find the attached .zip[ogl_arb_shader_simple_vs2ps.vcproj.7.10.zip] file contain source code of my application.

Are you using AMD drivers? I had someone confirm a memory leak for me a few months back. Not sure if it has been fixed yet.

It may be a memory leak in the driver or it may not. There are specific documented conditions which limit when memory used by shaders is released, so you should confirm that your code is correct so far as the documentation is concerned.

glDeleteProgram: http://www.opengl.org/sdk/docs/man/xhtml/glDeleteProgram.xml

If a program object is in use as part of current rendering state, it will be flagged for deletion, but it will not be deleted until it is no longer part of current state for any rendering context. If a program object to be deleted has shader objects attached to it, those shader objects will be automatically detached but not deleted unless they have already been flagged for deletion by a previous call to glDeleteShader

glDeleteShader: http://www.opengl.org/sdk/docs/man/xhtml/glDeleteShader.xml

If a shader object to be deleted is attached to a program object, it will be flagged for deletion, but it will not be deleted until it is no longer attached to any program object, for any rendering context (i.e., it must be detached from wherever it was attached before it will be deleted).

So the first thing to check is that you detach the shaders from the program, then delete the shaders, then use glUseProgram (0), then delete the program.

Just a short comment:
It is meaningless what you want to do!

My friendly advice is to get back to the previous solution.
Create shaders/programs in the initialization routines. If you don’t need shaders as separate objects delete them as soon as they are attached to the program, and the program is linked successfully. Delete program in the Release routine.

If you are trying to create/attach shaders/compile/link/select/deselect/delete programs in each frame you’ll get a very poor frame rate. If having one figure FPS is what you want to achieve, than it is ok.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.