ReferenceCountedArray, ReferenceCountedObjectPtr and safe usage

Hi, I use designIIRLowpassHighOrderButterworthMethod to get a ReferenceCountedArray of IIR::Coefficients in order to create a few IIR::Filter objects. I finally have it working, but for a while I was getting what I suspect to be memory leak issues, the type where you can view it in the debugger, correctly initialized variables would become garbage.

coeffs = juce::dsp::FilterDesign<float>::designIIRLowpassHighOrderButterworthMethod(3200, 48000, 3);
jassert(coeffs.size() == 2);
ReferenceCountedObjectPtr<juce::dsp::IIR::Coefficients<float>> somePtr = coeffs[0];
filterOne = juce::dsp::IIR::Filter<float>(somePtr);
ReferenceCountedObjectPtr<juce::dsp::IIR::Coefficients<float>> anotherPtr = coeffs[1];
filterTwo = juce::dsp::IIR::Filter<float>(anotherPtr);

This was the initial code, that would cause runtime crashes all over the place. I fixed it by adding this line at the bottom.

coeffs.clear();

I’d like to know why that solves things.