This project has moved and is read-only. For the latest updates, please go here.

MemoryAllocationError calling waveInOpen

May 12, 2012 at 8:06 PM

I have an app that uses WaveIn to record audio. It records it in chunks... to do this, it calls:


... and then after a few seconds, it calls:


Right after it calls waveIn.StopRecording(), it allocates a new WaveIn object and calls StartRecording() on it to start recording the next chunk of audio.

Is this a reasonable approach?

What I'm finding is that occassionally, this happens when calling StartRecording():

Error while starting recording: MemoryAllocationError calling waveInOpen

at NAudio.MmException.Try(MmResult result, String function)

at NAudio.Wave.WaveIn.OpenWaveInDevice()

at NAudio.Wave.WaveIn.StartRecording()

Any thoughts on how to avoid this?

May 14, 2012 at 11:47 AM

You need to properly dispose of the old WaveIn to avoid memory leaks. Also, it would be better to use just one instance of WaveIn, calling Start and Stop. An alternative is to just call StartRecording once and ignore the DataAvailable events when you don't want data.