问题描述
我的服务器代码中有一部分:
There is part of my server code:
IDictionaryEnumerator enumerator = GetHashtable(userlist).GetEnumerator();
while (enumerator.MoveNext())
{
DictionaryEntry current = (DictionaryEntry)enumerator.Current;
try
{
GClient client = (GClient)current.Value;
Console.WriteLine("Money: " + client.money);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
代码执行多次(超过10000次)后,ANTS Memory Profiler显示哈希表和存储桶泄漏,添加了许多userlist枚举器,但尚未收集,此外,服务器也开始运行缓慢,
此代码中有很多NullReferenceException
After the code is executed many times(More than 10000), the ANTS Memory Profiler shown that the hashtable+bucket are leaked, Many of userlist enumerator were added and haven't been collected, Also, the server started being laggy and
having lots of NullReferenceException from this code
有人知道这个问题吗?
推荐答案
代码在哪里?
我唯一能想到的是,您正在从其他线程修改哈希表,并且最终导致哈希表损坏.尽管很难解释内存泄漏",但是此代码中没有任何可能导致泄漏的东西.
The only thing I can think of is that you're modifying the hashtable from other threads and you end up with a corrupted hashtable. Though it's hard to explain the "memory leak", there's nothing in this code that could cause leaks.
这篇关于C#Hashtable GetEnumerator错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!