OpenGL GPU Memory Leak Windows


#1

First off, I’ve had a look around and it seems no one else is experiencing this issue so that generally means I’m doing something wrong but I can’t see what! It relates to a GPU memory leak, not system RAM.

I can create an audio plugin straight from Producer, then add a very simple component that inherits OpenGLRenderer.

In the constructor of this component I do the usual:

openGLContext.setOpenGLVersionRequired(juce::OpenGLContext::OpenGLVersion::defaultGLVersion);
openGLContext.setRenderer(this);
openGLContext.attachTo(*this);
openGLContext.setContinuousRepainting(false);

In the destructor I do more of the usual:

openGLContext.detach();

In newOpenGLContextCreated I setup whatever I need - textures, shaders e.t.c.

In openGLContextClosing I release/destroy everything.

This component also has an instance of OpenGLContext.

Then the PluginEditor has an instance of this OpenGLRenderer component.

All will draw perfectly, however when this plugin is loaded in the Demo Host or a DAW then on closing the plugin window gDEbugger will report a memory leak on the GPU. It’s clear that a context is deleted before any clean up and so it seems as per usual with anything OpenGL related it depends on the driver implementation as to whether memory is actually cleaned up. I’d prefer to assume that memory isn’t cleaned up.

I noticed this is not a problem with an OpenGLRenderer in the Juce Demo. Digging down into the code it appears that when a native Windows’ window is created from line 161 juce_OpenGL_win32.h ultimately at line 1368 in juce_win32_Windowing.cpp it has a parent window set. When closing the Juce Demo, that window is a desktop window and the child window is deleted first (the one with the OpenGLContext), however when opening the plugin in a DAW or the Juce Demo Host, the window is not a desktop window and so the parent gets deleted along with the child (again the one with the OpenGLContext). Thus the context has gone before there can be any cleanup e.g. texture releases.

I have a solution for this but something doesn’t feel right…I’d really appreciate a sanity check if anyone has the time as this one nearly drove me (more) nuts. Many thanks.


#2

I was always under the impression that deleting the OpenGL context will also delete all the resources. Sure, formally, it’s a GPU memory leak as there shouldn’t be any more resources when closing the context but it shouldn’t have any practical implications. Once you close the editor the resources will be released. Right?


#3

Hi Fabian, Many thanks for the swift response, I think you’re right, I had previously read this post:

but of course looking at gDEuggers output which said I was leaking every single OpenGL resource I used wasn’t exactly reassuring! I guess it wouldn’t be too much of a stretch to think this might be an issue on some weird and wonderful graphics card though, but time will tell…

Cheers.