I am trying to track down a memory leak when I play lots of mp3 files. If I don't play files, the memory usage is flat, but when I play files, the memory usage slowly climbs.
OS = Windows XP SP3
Application = ASP.NET
NAudio = 1.7
For each file, here is what I use to start the playback:
```
Public Sub PlayFile(ByRef fileName As String) ' play one file
waveOutDevice = New WaveOutEvent()
fReader = New AudioFileReader(fileName)
mainOutputStream = New WaveChannel32(fReader) ' tie the file reader to the output stream
mainOutputStream.PadWithZeroes = False ' need this to detect eof
waveOutDevice.Init(mainOutputStream) ' tie output stream to output device
waveOutDevice.Play()
End Sub
```
and here is the code that I call once the file has finished:
```
Public Sub Cleanup()
If (waveOutDevice IsNot Nothing) Then
If waveOutDevice.PlaybackState <> PlaybackState.Stopped Then
waveOutDevice.Stop() ' stop playing around
End If
End If
If (mainOutputStream IsNot Nothing) Then ' clean up output streams
mainOutputStream.Close()
mainOutputStream.Dispose() ' also disposes the file reader
mainOutputStream = Nothing
End If
If (waveOutDevice IsNot Nothing) Then ' clean up waveout device
waveOutDevice.Dispose()
waveOutDevice = Nothing
End If
End Sub
```
Any advice or directions appreciated.
Jake
Comments: This is not a memory leak. You can GC.Collect() to free memory by force, or it should be freed anyway automatically in some time.
OS = Windows XP SP3
Application = ASP.NET
NAudio = 1.7
For each file, here is what I use to start the playback:
```
Public Sub PlayFile(ByRef fileName As String) ' play one file
waveOutDevice = New WaveOutEvent()
fReader = New AudioFileReader(fileName)
mainOutputStream = New WaveChannel32(fReader) ' tie the file reader to the output stream
mainOutputStream.PadWithZeroes = False ' need this to detect eof
waveOutDevice.Init(mainOutputStream) ' tie output stream to output device
waveOutDevice.Play()
End Sub
```
and here is the code that I call once the file has finished:
```
Public Sub Cleanup()
If (waveOutDevice IsNot Nothing) Then
If waveOutDevice.PlaybackState <> PlaybackState.Stopped Then
waveOutDevice.Stop() ' stop playing around
End If
End If
If (mainOutputStream IsNot Nothing) Then ' clean up output streams
mainOutputStream.Close()
mainOutputStream.Dispose() ' also disposes the file reader
mainOutputStream = Nothing
End If
If (waveOutDevice IsNot Nothing) Then ' clean up waveout device
waveOutDevice.Dispose()
waveOutDevice = Nothing
End If
End Sub
```
Any advice or directions appreciated.
Jake
Comments: This is not a memory leak. You can GC.Collect() to free memory by force, or it should be freed anyway automatically in some time.