Leaking WavAudioFormatReader objects


#1

I'm trying to work out when to delete a WavAudioFormatReader created by WavAudioFormat::createReaderFor. I do the following:


File file(filename);
FileInputStream stream(file);
WavAudioFormat format;
AudioFormatReader *reader = format.createReaderFor(stream, false);
synth.addSound(new SamplerSound(name, *reader, notes, root, attack, release, 10.0));
delete reader;

The problem is delete reader causes the runtime to throw an assertion about bad heap blocks. I tried storing the reader in an array owned by the object that has this code, but when it comes to cleanup the readers, I get a crash trying to access 0xffffffff. So... when can I safely delete the reader? If I don't then JUCE reports I've leaked this object.

Apart from this, I've rewritten my Melody Mine application using JUCE and can create MIDI files or play sample wave files; I'm impressed I've got this to work so far without having to resort to external libraries yet!


#2

The answer is the input stream; the reader tries to delete it, so it needs to be allocated.