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:
In the destructor I do more of the usual:
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.