This project has moved. For the latest updates, please go here.

Unmanaged memory keeps growing

Nov 18, 2015 at 2:09 AM
I have an application that plays mp3 or wav files using NAudio and overtime the unmanaged memory usage of my app consistently keeps growing. I have used a memory profiler and it appears the MSACM32.dll (Microsoft ACM Audio Filter) is the cause of the unmanaged memory growth. If I remove the audio playback code I do not see the unmanaged memory usage grow (My app also uses NAudio to record audio from 1 or more sound cards and that works fine). This is on a Windows 7 64-bit machine running 32-bit code.

My app plays lots of unique audio clips normally in the 30-60 second range. In the past 2 days it has played just over 10,000 mp3 files and MSACM32 is using 36MB of unmanaged memory and growing.
Managed Heap memory usage over that same 2 day time frame grew by 143KB and totals 3.8MB.

I have tried various different code implementations to play the mp3 files always making sure any AudioFileReader and WaveOutEvent objects are disposed of and nothing seems to make a difference after many thousands of files.

I'm currently using the "Fire and Forget Audio Playback" from, but I'm still seeing the Unmanaged memory usage keep growing.

As a test instead of reading the mp3 or wav file with an AudioFileReader I used a SignalGenerator to generate a tone for a few seconds. The Unmanaged memory usage did not grow so that leaves me to believe the issue is in the AudioFileReader area.

Has anyone ever ran into this issue playing back a large number of files?
Nov 19, 2015 at 6:47 AM
The nature of .NET is that it has a garbage collector. so just because memory is growing, doesn't necessarily mean there is a leak.
You could try a simple test to see if it is the AudioFileReader by writing an app that repeatedly opens an MP3 file, reads it to the end, and disposes it. That would fairly quickly reveal if there is a memory leak in the ACM interop somewhere.
Nov 20, 2015 at 2:36 AM
The MSACM32.dll memory usage is Unmanaged so the .NET garbage collector will not manage that memory. It has to be explicitly allocated and freed by the code using it.

Also, when I take a memory snapshot the profiler triggers a full garbage collection before taking the snapshot. I just took another snapshot and MSACM32.dll is now using 73MB after 4 days.

I will look into creating a test program, but that will take a few days due to my schedule.

Thanks for the response.
Nov 21, 2015 at 9:54 PM
Edited Nov 21, 2015 at 9:57 PM
If MSACM32.dll is the problem, then the problem is for sure in the MP3FileReader that uses ACM codecs installed on your OS.

If you can´t fix this unmanaged issue, you should give a chance, which is fully managed.
Nov 23, 2015 at 8:36 AM
are you definitely disposing all your AudioFileReader instances?
Nov 25, 2015 at 1:31 AM
Yes, all AudioFileReader are getting disposed of after they finish reading. I used the memory profiler to verify that there is only one AudioFileReader live instance when my application is playing audio. When no audio is playing there are no live instances of AudioFileReader.

Instead of using AudioFileReader I switched to MediaFoundationReader and memory usage does not seem to be growing after two days. I do loose XP support, but that's not a huge issue. I will keep testing MediaFoundationReader and see if the memory usage grows.