Beginner question: 'setContentOwned' and 'deleteAndZero'


#1

Hi,

I am trying to compile/run the audio demo part of the JuceDemo project. When my main component is AudioDemoTabComponent (all tabs of the audio demo), everything is ok. I use it by putting these lines in the constructor of my MainAppWindow:

Component* audioDemo = new AudioDemoTabComponent (); setContentOwned (audioDemo, true);
However, if I try to use only one tab as my main component, the AudioDemoPlaybackPage component, the app crashes when I close it. I use it by putting these lines (as before, in the constructor of MainAppWindow):

audioDemo = new AudioDemoPlaybackPage(_deviceManager); _deviceManager.initialise (2, 2, 0, true, String::empty, 0);
Where _deviceManager is a class member of type AudioDeviceManager.

The crash happens in the line

in the destructor of AudioDemoPlaybackPage. The crash does not happen if I add

in the MainAppWindow’s destructor (of course then audioDemo must become a class member).

My question is, why in the first case using setContentOwned works ok (is responsible for deleting the allocated audioDemo), and in the 2nd case I have to delete it myself?