Maybe this is not a good question to post but I am kinda desperate. I have a little piece of code, and i have a memory leak, but i don't know how to overcome it. please help.
var nPiece = stream.Length / BufferLen;
var lastPieceLen = stream.Length - (nPiece * BufferLen);
for (int i = 0; i < nPiece + 1; i++)
{
var buffer = new byte[i != nPiece ? BufferLen : lastPieceLen];
stream.Read(buffer, 0, buffer.Length);
using (var chunk = new MemoryStream(buffer))
SsClient.SendChunk(i != nPiece ? (i + 1).ToString() : ((i + 1) + "last"), SsSession, chunk);
buffer = null;
GC.Collect();
}
I split a large stream into smaller chunks and send them to a WCF service over SsClient.SendChunk() method. Let's say I have a file which is 700 mb, i split it into 7 pieces of 100 mb chunks, and send them one by one. but after this method is done there is around 400 mb in memory which i see as memory leak. when i debug it i see memory gets filled with chunk right after SendChunk method of web service. When the method finished here I'm left with the memory leak. GC.collect() doesn't seem to work either. I didn't even understand why there is 400 mb leftover of 700 mb file? maybe that might give some clues i don't know.
any ideas?