Windows服务内存泄漏问题. [英] Windows service memory leak problem..

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

问题描述

我已经在c#.net中开发了Windows服务,该服务基本上是客户端服务器应用程序.客户端在这里发送请求,服务器使用第三方API在本地数据库中查找.包装器类用于调用该API的功能.我的问题是,如果我运行Windows服务在while循环中发送客户端请求数小时,则内存会增加,但是如果我停止客户端程序,则内存根本不会减少(它保持在该级别).尽管我对控制台应用程序做了同样的事情,但随着内存的减少,它似乎可以正常工作.然后,我使用内存探查器(perfmon,蚂蚁),但我无法提出解决方案.我真的很困惑,因为我的控制台应用程序可以正常工作..但是Windows服务不是(除了我在ON_Start上编写了我的控制台应用程序的Main之外,这基本上是相同的代码).

*这是一个线程服务器,我为每个客户端创建一个线程,

*我使用tcpclient类.

*在内存探查器中,专用字节在增加,但是.net堆字节数保持不变.但是,我在一个循环中用另一个控制台程序调用了该包装器类,但没有发现任何内存泄漏.令人困惑的是控制台应用程序正常工作.

*我重写了该包装类的dispose方法,并且每当我使用该对象时都调用该dispose方法.

I have developed a windows service in c#.net which is basically a client server application. Here client sends request and server looks up in the local database using a third party API. A wrapper class is used to call the function of that API. My problem is, if i run that windows service send client request in a while loop for hours the memory in increasing but if i stop the client program memory is not decreasing at all(it remains on that level). Although I have done the same thing with a console application which seems to work fine as its memory are decreasing. Then i use memory profiler(perfmon, ants) but i cannot come up with a solution. I am really confused as my console application works fine ..but windows service is not(which is basically the same code except i have written the Main of my console application on ON_Start).

*It is a threaded server, for every client I creates one thread,

*I use tcpclient class.

*In the memory profiler private bytes are increasing, but # of .net heap bytes remains the same. but, I had called that wrapper class with another console program in a loop i didn''t find any memory leak. confusing thing is console application working correctly.

* I override the dispose method of that wrapper class and latter call that dispose method whenever i used that object.

推荐答案

我认为您的问题涉及到您的问题线程..很可能与处置"相关联...检查看看实际上要处置哪些对象...听起来好像您的处置被其他线程中的错误对象调用了...

使用图案

I think your issues are involved in your Threading.. Most likely tied into the Disposal... check to see which objects are actually getting disposed of... It sounds like your dispose is being called oin the wrong object from a different thread...

Use the pattern

class myThreadWorkerClass :System.Threading.Thread
{
//blah..
}



我发现这有助于使我保持心态,即我在此垂直线程上声明内存,并且还有助于解决跨线程问题...

希望对您有帮助
(是的,我知道自从该线程处于活动状态"以来已经有一段时间了:〜)



I find this helps to keep me in the mindset that i am declaring memory on this perticular thread, and it also helps with cross thread problems...

hope that it is helpfull
(yes I know it has been a while since this thread was "active" :~)


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

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