跟踪.NET Windows服务内存泄漏 [英] Tracking Down a .NET Windows Service Memory Leak

查看:89
本文介绍了跟踪.NET Windows服务内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将Windows服务安装到生产环境中之前,我一直在寻找可以执行的可靠测试,以确保我的代码不包含内存泄漏. 但是,我在网上可以找到的全部是使用任务管理器查看已用内存或某些付费内存分析器工具.

Before installing my windows service in production, I was looking for reliable tests that I can perform to make sure my code doesn't contain memory leaks. However, All what I can find on the net was using task manager to look at used memory or some paid memory profiler tools.

根据我的理解,查看任务管理器并没有真正的帮助,并且无法确认内存泄漏(如果有的话).

From my understanding, looking at the task manager is not really helpful and cannot confirm the memory leakage (in case, there is).

  1. 如何确认是否存在内存泄漏?

是否有免费的工具来查找内存泄漏的根源?

Is there any free tools to find the source of memory leaks?

注意:我正在使用.Net Framework 4.6和Visual Studio 2015社区

Note: I'm using .Net Framework 4.6 and Visual Studio 2015 Community

推荐答案

那么您可以使用任务管理器. GC应用程序可能会泄漏内存,并且会在那里显示.

Well you can use task manager. GC apps can leak memory, and it will show there.

但是...

有一个免费工具,它来自Microsoft,而且很棒.这是所有泄漏引用的程序的必需使用.搜索MS网站.

There is a free tool, and it's from Microsoft, and it's awesome. This is a must-use for all programs that leak references. Search MS' site.

泄漏引用意味着您忘记将对象引用设置为null,否则它们永远不会离开范围,这在垃圾收集的语言中几乎有可能会发生-列表正在建立且未清除,事件处理程序指向委托等

Leaking references means you forget to set object references to null, or they never leave scope, and this is almost as likely to occur in Garbage collected languages as not - lists building up and not clearing, event handlers pointing to delegates, etc.

这等效于GC的内存泄漏,并且结果相同.该程序告诉您哪些引用占用了大量内存-您将知道是否应该那样做,否则,您可以查找它们并解决问题!

It's the GC equivalent of memory leaks and has the same result. This program tells you what references are taking up tons of memory - and you will know if it's supposed to be that way or not, and if not, you can go find them and fix the problem!

它甚至可以清晰地显示出哪些对象分配了什么内存(以便您可以跟踪错误).我相信如果您需要解释的话,还会有YouTube用户.

It even has a cool visualization of what objects allocate what memory (so you can track down mistakes). I believe there are youtubes of this if you need an explanation.

带有下载链接的维基百科页面...

注意:您可能必须将应用程序 not 作为服务运行才能使用它.它首先启动,然后运行您的应用程序.您可以使用TopShelf或仅将胆量放入从EXE运行的dll中,以实现服务集成(服务主机模式).

NOTE: You will likely have to run your app not as a service to use this. It starts first and then runs your app. You can do this with TopShelf or by just putting the guts in a dll that runs from an EXE that implments the service integrations (service host pattern).

这篇关于跟踪.NET Windows服务内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆