Search code examples
c#grpcgrpc-dotnet

GRPC - Do I need to dispose or close the IService when I finish using it?


IService service = MyGrpcChannel.CreateGrpcService<IService>();
long[] ids = service.GetIds();

Do I need to do something to close/destroy the IService when I finish to use it?


Solution

  • It's not necessary, the service is a thin veneer on the channel:

    https://github.com/protobuf-net/protobuf-net.Grpc/issues/166

    I also made a test creating 1 million services:

    for(int i = 0; i <= 1000000; i++)
    {
        MyGrpcChannel.CreateGrpcService<IService>().GetIds();
    }
    

    No memory leak on the task manager. At the start of execution it was using 100mb and at the end too.