My audio app runs fine and throws an exception when it closes. I am having memory leakage and I know I need to use std::unique_ptr to stop this but this is not working for the MidiOutput class. I have declared my object as follows:
But you might want to avoid initializing the device right in your class members. There’s obviously no guarantee the device number 0 will always work. (The unique_ptr would end up containing a null pointer in that case, though, so you can still check that later, though…)
Also you don’t need to set the unique_ptr immediately. It is perfectly fine to use the default constructor, that will point to nullptr.
std::unique_ptr<MidiOutput> moutput;
// later
if (moutput == nullptr && MidiOutput::getDevices().size() > 0)
{
moutput.reset (MidiOutput::openDevice (MidiOutput::getDefaultDeviceIndex()));
}
You still should test each time you try to use the device, like Xenakios said correctly, if there was no MidiOutput available, it can still be a nullptr…