Leaked object: NSViewAttachment


#1

Hi, in my application i sometimes need to open an instance of the following class which hosts an editor of an AudioPluginInstance.
Everything works fine until i close the application where i always get the following warning:

*** Leaked objects detected: 1 instance(s) of class NSViewAttachment
JUCE Assertion failure in juce_LeakedObjectDetector.h:97

Closing the window directly works on first sight but when closing the application i also get that warning, therefore something is not cleaned up correctly around the editor i guess.

How can i correctly clean and close that desktop window too? Thanks for any hints.

class PresetsListComponent::SynthWindow  : public DocumentWindow
{
public:
    SynthWindow (PresetsListComponent& owner_, ScopedPointer<AudioPluginInstance> instance_)
    : DocumentWindow ("", Colours::lightgrey, DocumentWindow::allButtons),
      owner (owner_),
      instance(instance_)
    {
        
        auto editor = instance->createEditor();
        auto bc = editor->getConstrainer();
        
        Component* component = new Component();
        component->addAndMakeVisible (editor);
        component->setBounds(0, 0, bc->getMinimumWidth(), bc->getMinimumHeight());
        
        setContentOwned(component, true);
        setResizable(false, false);
        
        setVisible (true);
    }
    
    ~SynthWindow()
    {
        clearContentComponent();
    }
    
    void closeButtonPressed()
    {
        owner.synthWindow = nullptr;
    }
    
private:
    PresetsListComponent& owner;
    ScopedPointer<AudioPluginInstance> instance;
    
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SynthWindow)
};

#2

Ok after several hours of finding a better solution i changed to the following version.
Now no leaking objects anymore, but only this message once when closing the application

JUCE Assertion failure in juce_AsyncUpdater.cpp:71

Anyone?

class PresetsListComponent::SynthWindow  : public DocumentWindow
{
public:
    SynthWindow (PresetsListComponent& owner_, AudioPluginInstance* instance_)
    : DocumentWindow ("", Colours::lightgrey, DocumentWindow::allButtons),
      owner (owner_),
      instance(instance_)
    {
        editor = instance_->createEditor();
        auto bc = editor->getConstrainer();
        editor->setBounds(0, 0, bc->getMinimumWidth(), bc->getMinimumHeight());
        
        setContentNonOwned(editor, true);
        setResizable(false, false);
        
        setVisible (true);
    }
    
    ~SynthWindow()
    {
        clearContentComponent();
    }
    
    void closeButtonPressed()
    {
        owner.synthWindow = nullptr;
    }
    
private:
    PresetsListComponent& owner;
    ScopedPointer<AudioPluginInstance> instance;
    ScopedPointer<AudioProcessorEditor> editor;
    
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SynthWindow)
};