如何找到在特定机器上的.NET远程处理内存泄漏?内存、在特定、机器上、NET

2023-09-07 00:41:03 作者:楆尒錇我1輩釨

内存泄漏是不是我的工作的一对夫妇发生的每一台机器上,但可靠,而且它看起来像接近10%的领域。

The memory leak is not happening on every machine, but reliably on a couple at my work, and it's looking like close to 10% in the field.

我有一个使用Windows服务来监视用户的输入启动警报,搭配可视化应用程序,只会坐在在系统托盘中,并允许用户进行配置更改的产品。

I have a product that uses a Windows service to monitor user input to launch alerts, paired with a visual application that serves only to sit in the system tray, and allow the user to make configuration changes.

我选择使用一个远程对象,分享两个进程之间的配置信息。在服务它被称为serviceConfig,并在可视化应用程序它被称为configData。对象是在服务器上创建的第一个,然后远程连接如下:

I chose to use a remoted object to share the configuration information between the two processes. In the service it is called serviceConfig, and in the visual application it is called configData. The object is created on the server first, and then remoted as follows:

try
{
    InitializeComponent();
    setAppInitDLL(thisDirectory);
    serviceConfig = new serviceConfigData();
    Regex getVersion = new Regex("Version=(?<ver>[^,]*)");
    if (getVersion.IsMatch(Assembly.GetExecutingAssembly().FullName))
    {
        serviceConfig.Version = new Version(getVersion.Match(Assembly.GetExecutingAssembly().FullName).Result("${ver}").ToString());
    }
    // Create the server channel for remoting serviceConfig.
    serverChannel = new TcpServerChannel(9090);
    ChannelServices.RegisterChannel(serverChannel, false);
    RemotingServices.Marshal(this.serviceConfig, "ServiceConfigData");
    baseLease = (ILease)RemotingServices.GetLifetimeService(serviceConfig);
    lock (Logger) { Logger.Write(String.Format("The name of the channel is {0}", serverChannel.ChannelName)); }

    lock (Logger) { Logger.Write("Exiting Constructor"); }
}
catch (Exception ex)
{
    lock (Logger) { Logger.Write(String.Format("Error in Constructor:{0}", ex.Message)); }
}

然后在可视化应用程序我有一个我连接使用私有对象:

Then in the visual application I have a private object that I connect using:

configData = (serviceConfigData)Activator.GetObject(typeof(serviceConfigData), "tcp://localhost:9090/ServiceConfigData");

在读取或写入到这个对象,我有catch语句的插座异常和远程处理异常,然后调用相同的语句。

When reading or writing to this object, I have catch statements for Socket Exceptions and Remoting Exceptions which then call this same statement.

在大多数机器,该工作没有内存泄漏,但对有些人来说非常迅速泄漏。所有机器在工作了.NET 3.5,有些是XP,一对夫妇的Vista系统。此问题已只出现在XP的机器,并在现场的机器都是XP。

On most machines this works without leaking memory, but on some it leaks very quickly. All machines at work have .NET 3.5, some are XP, a couple are Vista. The problem has only been seen on XP machines, and the machines in the field are all XP.

我应该在哪里寻找,并作为次要的问题,我应该利用这个东西完全不同的任​​何想法?

Any ideas where I should be looking, and as a secondary question, should I be using something completely different from this?

推荐答案

我首先想到的是个人主页上你看到的泄漏与类似的红门的内存分析器的。

My first thought would be to profile the application on the machines you're seeing the leak with something like Red Gate's Memory Profiler.

这将是一个很多比试图去猜测泄漏可能会更可靠。

It'll be a lot more reliable than attempting to guess what the leak might be.

至于艇员选拔正确的技术,如果你所有的机器将有.NET 3.5安装,您可能要考虑迁移到WCF(主要是命名管道),为您的进程间通信。检查this SO 发布更多详细信息...

As for chosing the right technology, if all your machines will have .NET 3.5 installed you might want to consider migrating to WCF (primarily Named Pipes) for your inter-process communication. Check this SO post for more detail...