Calling wglMakeCurrent cause memory leak?

I recently found a memory leak in my project, and when I tried to comments the wglMakeCurrent calls I found that the memory leak was gone.

I’m currently wondering if I’m using it right. I’m using a thread pool with multiple tasks to execute and one of this task o render a scene with openGL. Since I never know which threads is going to execute this task I’m calling wglMakeCurrent(DC, RC) each frames just before using openGL, and I’m calling wglMakeCurrent(NULL,NULL) at the end of the frame. Which means that the openGL context is set and unset around 60 times by second.

However, there is a memory leaks. Is it a bug, or maybe I should not call wglMakeCurrent each frames and bind this task exclusively to the main thread ?

I found that only using wglMakeCurrent(DC, RC) without calling wglMakeCurrent(NULL,NULL) or calling wglMakeCurrent(NULL,NULL) without using wglMakeCurrent(DC, RC) doesn’t cause a memory leak.

My graphic device is a NVidia 285 GTX

That must be a bug, but who is responsible for it we have to determine yet.

Without calling wglMakeCurrent(NULL,NULL), you cannot use that context from the other thread. Are you sure that wglMakeCurrent() creates a memory leak? If the context is not active no one GL call can succeed.

The particular graphics card is not important in this problem, but rather the driver. You also have to give more details about the implementation. Of course, a faster solution is to bind GL context just to a single thread and send commands from the others. wglMakeCurrent() calls certainly reduce the execution speed.

I found the problem!

My memory leak was actually elsewhere. When I decided to remove all graphic draw calls I tried to keep calling wglMakeCurrent without calling SwapBuffers with SDL. However I found that calling wglMakeCurrent without calling the SDL SwapBuffers cause a memory leak and I tough it was THE memory leak.

Finally I fixed the memory leak in my code and it work perfectly. Thanks for your help =)

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