我正在使用 ILSpy 对一个用 vb.net 编写的旧 Windows 服务进行逆向工程。我想用 C# 重写遗留服务。原始服务泄漏内存。
当我查看源代码时,服务类中有以下声明:
private static List<WeakReference> __ENCList = new List<WeakReference>();
此列表仅在构造函数中使用如下(imineRun是服务类):
List<WeakReference> _ENCList = imineRun.__ENCList;
Monitor.Enter(_ENCList);
try
{
imineRun.__ENCList.Add(new WeakReference(this));
}
finally
{
Monitor.Exit(_ENCList);
}
这个列表会导致内存泄漏吗?是否需要此列表?它的目的是什么?
最佳答案
由于它在您的 代码中无处使用,因此它不是服务的必要部分。现在,我环顾四周,就像我之前在 IL 输出中看到的那样,显然你偶然发现了 Edit-and-Continue code which was left in the service .根据博客文章,它显然可能是高内存使用率的罪魁祸首。
Having modules built in debug mode running on a Production server is never a good idea. And as it turned out in this case, the debug mode modules combined with the fact that these modules implement the __ENCLIST helper class for Visual Studio’s Edit and Continue feature.
我敢打赌它是在完全调试支持下编译的,而不是作为发布可执行文件。
您可以放心地在您的端口中忽略此代码。
关于c# - 是否需要 static List<WeakReference>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7982219/