The TabbedComponent cause memory leak?


Hello, everyone! I got problem when using the TabbedComponent, below is the MainContentComponent:

class MainContentComponent   : public Component
        : spTc(TabbedButtonBar::TabsAtTop)
        spTc.addTab("Main", Colour(0xffeeddff), new TextButton("hello"), false);
        setSize(500, 400);


    void paint(Graphics& g)
        g.fillAll (Colour (0xffeeddff));

    void resized()

    TabbedComponent spTc;

This code get an unhandled exception when exiting, The code crashed at  juce_win32_Windowing.cpp Line 1643.

Then I changed the TabbedComponent spTc to SafePointer<TabbedComponent> spTc, and then the program get a memory leak of when exiting: *** Leaked objects detected: 1 instance(s) of class TabBarButton

How to use the TabbedComponent, can someone help me?



You've allocated a new TextButton with addTab() without keeping a reference to it for later deletion. If you're going to do this then you need to set deleteComponentWhenNotNeeded to true so the TabbedComponent takes ownership and deletes it for you.


The leaked object is the TabBarButton, not the TextButton.  I did firstly set the deleteComponentWhenNotNeeded to true . That cause the same leak of TabBarButton.