COffscreenContext memory leak?


Using VSTGUI 4.10 and the vst3 SDK 3.7.2, OSX 10.15.6. I have a question about storing a CBitmap created from COffscreenContext…

SharedPointer<CBitmap> _bitmap;
void drawSomething( CView *view,  SharedPointer<COffscreenContext> context );
void captureBitmap( CView *view )
    CFrame *frame = view->getFrame();
    if (!frame)
    const CRect &view_rect = view->getViewSize();
    SharedPointer<COffscreenContext> context = COffscreenContext::create( frame, view_rect.getWidth(), view_rect.getHeight(), 4. );

    drawSomething( view, context );
    _bitmap = context->getBitmap();
    // _bitmap->remember();  //  <--- Is this needed?

I’m seeing different behavior between my VST3 and AUv2 plug-ins whether _bitmap->remember() is called or not.

It seems to me that the _bitmap shared pointer shouldn’t need an explicit remember(). However for AUv2, there is an intermittent crash after the plug-in is de-instantiated. The backtrace shows the crash inside CFRelease. If I then either comment out the line CGImageRelease (image) in the CGBitmap destructor, or call _bitmap->remember() above, then the crash does not happen.

For VST3, calling _bitmap->remember() produces a memory leak in VST3PluginTestHost as I’d expect. So I’m wondering if there’s a problem with my code above or if the problem exists externally. Any insight?

Thank you!

Maybe use the freestanding renderBitmapOffscreen function from coffscreencontext.h: vstgui/coffscreencontext.h at develop · steinbergmedia/vstgui · GitHub

It does what you want without a leak.