Click here to Skip to main content
15,886,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on mp3 streaming. I used Mark Heath's NAudio.dll for this project. But streamed mp3 frames must be decompressed to listen. I m using List and byte array to storage data. So that ram using is over 200 mb on every mp3 playing. But main problem is my code throw OutOfMemoryException exception after 3 or 4 song played. I tried "=null and Clear()" method but it seems it doesnt work.How can I fix this problem. Thanks in advance.
Posted
Updated 24-Apr-15 13:13pm
v3
Comments
Richard MacCutchan 24-Apr-15 13:08pm    
Stack overflow is usually caused by overuse of local variables instead of heap storage.
Sascha Lefèvre 24-Apr-15 21:16pm    
Please add the relevant code to your question.

1 solution

Stack overflow has nothing to do with the size of Lists, or arrays of any description - in C# these are always Reference types, and as such are stored on the Heap, not the stack.

So look at your code: the most likely reason for a Stack Overflow Exception is that you have some inadvertent recursion eating your stack rather than anything directly to do with the structures you are storing data in.
 
Share this answer
 
Comments
Amt-Coder 24-Apr-15 19:12pm    
sorry I wrote it wrong. It should be OutOfMemoryException. I have edited
OriginalGriff 25-Apr-15 5:03am    
You gotta be accurate about these things, my friend! :laugh:

That's a whole new world of pain...
Start by looking at your .NET framework version: prior to V4.5 the Large Object Heap wasn't compacted, so it's possible that a change to the framework version will slow or prevent the problem (if it's the heap becoming fragmented so it can't allocate a new block of the requested size). It's unlikely, but it's generally simple to change and could be diagnostic.

After that, you need to know exactly what is going on - and that's complicated. Start with a memory profiler - VS 2012 had one built in:
http://blogs.msdn.com/b/dotnet/archive/2013/04/04/net-memory-allocation-profiling-with-visual-studio-2012.aspx
And see if that tells you what objects you are allocating.

But...I'd guess it's that you are allocating a lot more memory than you think, and not destroying the references, or that you are trying to allocate far, far too big a chunk of memory (no single .NET object can be larger than 2GB, and an array of bytes is a single object for example). Start with the profiler and see if you can work out what is being allocated for a single track.

Without your code? I can't do much from here!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900