When I run the following code in a unit test, I see that private bytes and working set slowly increase in Performance Monitor and unmanaged memory slowly rises in dotMemory. I've decompiled the source in dotPeek and can't seem to find anything out of the ordinary. Any ideas? Here's the code:
[TestMethod]
public void TestEnumeratorMoveNext()
{
//Dictionary<string, int>[] outDict = new Dictionary<string, int>[32].Select(x => x = new int[100].ToDictionary(y => Guid.NewGuid().ToString())).ToArray();
var outDict = new Dictionary<string, int>[32];
for (int j = 0; j < 32; j++)
{
outDict[j] = new Dictionary<string, int>();
for(int q = 0; q < 100; q++)
{
outDict[j].Add(Guid.NewGuid().ToString(), 0);
}
}
for (int i = 0; i < 10000; i++)
{
var enumerator = new Enumerator<string, int>(outDict);
while (enumerator.MoveNext()) { }
Thread.Sleep(1000 / 60);
}
}
public struct Enumerator<TKey, TValue> : IEnumerator<KeyValuePair<TKey, TValue>>
{
private Dictionary<TKey, TValue>[] dictionary;
private int partition;
private IEnumerator<KeyValuePair<TKey, TValue>> enumerator;
private bool moveNext;
private int totalPartitions;
internal Enumerator(Dictionary<TKey, TValue>[] dictionary)
{
this.dictionary = dictionary;
this.totalPartitions = dictionary.Count();
partition = 0;
enumerator = new Dictionary<TKey, TValue>.Enumerator();
moveNext = false;
}
public bool MoveNext()
{
if (partition < totalPartitions)
{
do
{
var outDict = dictionary[partition];
if (!moveNext)
enumerator = outDict.GetEnumerator();
moveNext = enumerator.MoveNext();
if (!moveNext)
{
enumerator.Dispose();
partition++;
}
} while (!moveNext && partition < totalPartitions);
return true;
}
partition = totalPartitions + 1;
enumerator = new Dictionary<TKey, TValue>.Enumerator();
moveNext = false;
return false;
}
public KeyValuePair<TKey, TValue> Current
{
get
{
return enumerator.Current;
}
}
public void Dispose()
{
enumerator.Dispose();
}
object IEnumerator.Current
{
get
{
return new KeyValuePair<TKey, TValue>(Current.Key, Current.Value);
}
}
public void Reset()
{
throw new NotSupportedException();
}
}
I appreciate any help anyone can give me. Thanks in advance.