Avoiding assertion from ReferenceCountedObject on shutdown

I'm not sure if I'm using ReferenceCountedObject correctly, as I always get this assertion on shutdown: https://github.com/julianstorer/JUCE/blob/7b1e8218008fe446525179e8b3b424ccbf3087a8/modules/juce_core/memory/juce_ReferenceCountedObject.h#L96

/** Decreases the object's reference count.
If the count gets to zero, the object will not be deleted, but this method
will return true, allowing the caller to take care of deletion.
*/
bool decReferenceCountWithoutDeleting() noexcept
{
jassert (getReferenceCount() > 0);
return --refCount == 0;
}

I have a base class that inherits from ReferenceCountedObject. It defines the typedef for e.g. BaseClass::Ptr. I also have a derived class (which does not define the typedef for itself).

In my MainComponent I declare DerivedClass::Ptr as a member.

DerivedClass::Ptr derivedClass;

In the constructor, it is assigned to an object like so

derivedClass = new DerivedClass(); 

Is there something I might be missing? Should it not be a member variable? Do I need to move the "new" assignment to Main.cpp and pass the DerivedClass::Ptr as an argument to MainComponent?

 

 

 

So I think this is something to do with have the ReferenceCountedObject::Ptr as a member of a ScopedPointer. Should that be causing an issue?