Beginner question regarding polymorphism and OwnedArray leaks


#1

As a beginner I am loving the framework so far and everything has fallen into place - thanks Jules and co.

I am having some trouble with using inheritance and the OwnedArray and know I am missing something simple. I have tried to condense the problem down into its simplest form:

class Base
{
};

class Derived : public Base
{
    OwnedArray<Base> list;
};

class Test
{
public:
    OwnedArray<Base> stuff;
};

Test t;
t.stuff.add(new Derived());

When I run this it leaks ie.

*** Leaked objects detected: 1 instance(s) of class OwnedArray

If I move 'OwnedArray<Base> list' into Base then no leak occurs.

I am not sure where my mistake is and am a bit stuck as I need inheritance for these classes.  

Any help would be gladly appreciated.


#2

Base needs a virtual destructor.


#3

Fixed. Thank you so much!

C++ has been a struggle for me so far, but using Juce has been a pleasure. You have created a great piece of software.

 


#4

:)