I have a memory leak in my application and investigating it has led me to believe there is a memory leak in netmf’s HashAlgorithm.
Sample:
using System;
using Microsoft.SPOT;
using System.Security.Cryptography;
using System.Threading;
namespace MemoryLeakTest
{
public class Program
{
public static void Main()
{
var text = "This is a test string to be hashed, to investigate if there's a memory leak";
Debug.EnableGCMessages(false);
uint availableMemory;
byte[] hash;
while (true)
{
using (var hashAlg = new HashAlgorithm(HashAlgorithmType.MD5))
{
hash = hashAlg.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text));
}
availableMemory = Debug.GC(true);
Debug.Print(availableMemory.ToString());
Thread.Sleep(1000);
}
}
}
}
Running that lets me watch the available memory decrease steadily for every loop.
Setting Debug.EnableGCMessages(true); and checking the GC output one can see that its
Type 1E (BINARY_BLOB_HEAD ):
thats growing.
Would appreciate if someone could verify this.
The ironic thing is that I use the System.Security.Cryptography.HashAlgorithm to sign my http-messages since there is a memory leak when using SSL. It strikes me now though… could the leaks be connected?