Why the handles getting more and more in WCF service? Handles leak ?
-
jeudi 19 juillet 2012 09:38
I found the handles of WCF program is increasing slowly in Windows Task Manager , no found memory leak,just Handles is increasing.
Once up go up won't fall down. I have no idea about this. if you know ,please help me .thanks.
Below is the test code,frequent call gettime ,you will see the handles getting more and more in the windows task manager.
class Program
{
static void Main(string[] args)
{
WebHttpBinding webHttpBinding = new WebHttpBinding();
webHttpBinding.MaxReceivedMessageSize = 67108864;
webHttpBinding.MaxBufferSize = 67108864;
webHttpBinding.ReaderQuotas.MaxArrayLength = 67108864;
webHttpBinding.ReaderQuotas.MaxStringContentLength = 67108864;
webHttpBinding.Security.Mode = WebHttpSecurityMode.None;
webHttpBinding.TransferMode = TransferMode.Streamed;
ServiceHost host = new ServiceHost(Test.Instance);
host.AddServiceEndpoint(typeof(Test), webHttpBinding, "http://localhost:8888");
foreach (ServiceEndpoint ep in host.Description.Endpoints)
{
ep.Behaviors.Add(new WebHttpBehavior());
}
host.Open();
Console.WriteLine("服务运行中...");
Console.ReadLine();
host.Close();
}
}
[ServiceContract]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
public class Test
{
private static Test instance = new Test();
public static Test Instance
{
get { return instance; }
}
[WebGet]
[OperationContract]
public string gettime()
{
return DateTime.Now.ToString("yyyy/MM/dd HH;mm:ss ms");
}
[WebGet]
[OperationContract]
public void gc()
{
GC.Collect();
Thread.Sleep(50);
GC.Collect();
Thread.Sleep(50);
GC.Collect();
}
}

