Memory leaks when adding AudioParameters to APVTS

Hi,

Everytime I make a code change and build, the first time the plugin runs causes Visual Studio to generate a long list of memory leak messages. This only happens the first time after a new build. After hours of hunting it turns out to be happening when adding parameters to the layout for the APVTS in the processor.

StepSequencerEngine::StepSequencerEngine() : AudioProcessor (BusesProperties().withInput("Input",  AudioChannelSet::stereo(), true)),
treeState(*this, nullptr, "PARAMETERS", createParameterLayout())
{

}

AudioProcessorValueTreeState::ParameterLayout StepSequencerEngine::createParameterLayout()
{
    std::vector<std::unique_ptr<RangedAudioParameter>> parameters;

    for(auto i = 0; i < 16; i++)
    {
        auto stepEncoderParameter = std::make_unique<AudioParameterInt>(IDs::PitchEncoderIDs[i], ParameterNames::PitchEncoderNames[i], 0, 127, DefaultValues::DefaultPitch);
    
        parameters.push_back(std::move(stepEncoderParameter));
    }

    return { parameters.begin(), parameters.end() };
}

^^ This is how the code looks when adding a paramter to the layout. I can’t see why this is causing an issue - can anyone shine a light on what might be problematic?

Cheers :slight_smile:

Could be :

  • Messages left in the Windows message queue
  • Memory leaks in some Juce internal code involving classes/data that doesn’t have the Juce memory leak detectors added
  • Some other plugin leaking in the host process or the host itself leaking

And maybe for some mysterious reasons you may be seeing those leaks only when your own plugin adds parameters into itself.

If you follow modern C++ practices carefully in your own code, you can probably ignore those Microsoft CRT detected leaks. (The detection can be turned off too…)

1 Like