c# - 是否需要 static List<WeakReference>?

标签 c# multithreading windows-services weak-references

我正在使用 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/

相关文章:

java - Thread类的start方法如何创建一个新的堆栈并执行run方法

java - 您在 Java 中遇到的最常见的并发问题是什么?

java - 奇怪的 JVM 线程挂起 - 有建议进行故障排除吗?

windows-services - 你怎么能调试这个错误? <服务名称> 服务无法启动。服务没有报错

c# - Windows 服务/无法为堆栈创建新的保护页

c# - 如何比较 2 个 .csv 文件并创建一个包含两个 csv 文件的部分的新 .csv?

c# - 如何将表达式编译成实际结果?

c# - 如何将 float 转换为小数,以便我可以上下显示数字

c# - 如何使用 .net 在远程计算机上启动/停止/重新启动 Windows 服务

c# - SpecExplorer 如何对 Microsoft.Modeling.Sequence 进行排序