简体   繁体   English

生产代码中的内存泄漏

[英]Memory leak in production Code

I have an application that runs as a windows service written using C# WCF. 我有一个使用C#WCF编写的作为Windows服务运行的应用程序。 In production code we are seeing a behavior where memory of the application grows slowly. 在生产代码中,我们看到了一种行为,其中应用程序的内存增长缓慢。 After reviewing the code, we found that there is a dictionary(concurrent) in which items gets added and not removed when job is finished. 查看代码后,我们发现有一个词典(并发),其中作业完成时添加而不删除项目。 Items are coming at the rate of around 100 per second. 物品以每秒约100个的速度进入。 Is there any way we can fix this problem without a code change? 没有更改代码,有什么方法可以解决此问题? or is there anyway that force the application to do garbage collection externally? 还是有强制应用程序从外部进行垃圾收集的? As I know there is no possibility but just posting it to get to know if anything there. 据我所知,只有发布它才能知道那里是否有任何可能性。

Item is a object of two properties (both are int). Item是具有两个属性的对象(均为int)。

If you move your app to be run by IIS as an app pool then you can configure app pool "recycle" . 如果将应用程序移动为由IIS作为应用程序池运行,则可以配置应用程序池“回收” One of the options is recycle on Virtual Memory usage , which how ASP deals with memory leaks. 选项之一是对虚拟内存使用量进行回收 ,这是ASP处理内存泄漏的方式。

You can also roll your own recycle, monitor your service memory usage and restart it when it reaches a threshold. 您还可以滚动自己的回收站,监视服务内存使用量,并在达到阈值时重新启动它。

Of course, app recycle does mean a process restart and your WCF service may react badly to this, your API calls may experience reduced SLAs, and worse you may expose unwanted behavior in your WCF service (bugs). 当然,应用程序回收确实意味着进程重新启动,并且您的WCF服务可能对此做出不良反应,您的API调用可能会遇到减少的SLA,并且更糟的是,您可能会暴露WCF服务中的有害行为(错误)。 But pretty much is the only way to 'control' a leak in production w/oa redeploy. 但是,这几乎是“控制”不带重新部署的生产中泄漏的唯一方法。

Ideally, fix the leak and re-deploy. 理想情况下,修复泄漏并重新部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM