2014-04-17 2 views
1

저는 WCF 클라이언트와 WCF 서비스를 가지고 있습니다. WCF 메서드를 지속적으로 호출 할 때 테스트 할 때 메모리 사용량은 매번 약 1MB 씩 증가합니다. 이 일을 어떻게 멈출 수 있습니까?WCF 메모리 사용량이 증가합니다.

MyService.JobsClient Client = new MyService.JobsClient(); 
Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ServicePath"]); 
Client.WCFGetSystemState(System.Environment.MachineName); 
+2

이 메모리를 나중에 회수하지 않습니까? GC는 필요에 따라 실행됩니다. 객체가 더 이상 사용되지 않을 때마다 실행되지 않습니다. –

+1

완료되면 클라이언트를 닫으시겠습니까? –

+0

@MikeStockdale 아니요. 문제가되었습니다. 감사합니다. – user1438082

답변

2

클라이언트를 사용한 후에는 반드시 닫아야합니다. 이 패턴을 따를 수 있습니다 (MSDN에서 가져옴) :

MyService.JobsClient Client = new MyService.JobsClient(); 
Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ServicePath"]); 
try 
{ 
    Client.WCFGetSystemState(System.Environment.MachineName); 
    Client.Close(); 
} 
catch (TimeoutException timeout) 
{ 
    // Handle the timeout exception. 
    Client.Abort(); 
} 
catch (CommunicationException commException) 
{ 
    // Handle the communication exception. 
    Client.Abort(); 
} 
관련 문제