I am currently reviewing the process of updating our CRM SDK product, and the main change I came across is that instead of connecting to the Xrm service and creating my IOrganizationService using a proven and reliable method:
var connection = CrmConnection.Parse(connectionString); var service = new OrganizationService(connection);
Now I need to use CrmServiceClient from the Tooling namespace:
CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString).OrganizationServiceProxy;
Now everything is fine, except for one important problem ... memory.
Using the older Xrm.Client method, you were able to specify the instance mode of the configuration service (which was used by default for ServiceConfigurationInstanceMode.PerName). This means that the service was reused if the same application was called create several times. This reduced the memory area. The image below shows the amount of allocated memory after a call to create a service instance 100 times

However, using the new method, you cannot set this instance mode anywhere, and it seems that a new connection is created each time, whether you want it or not. Here are the results of the same test: 
As you can see, with each new connection more and more memory is allocated. I canβt see that I can say that it is reusing the service.
So I basically ask, am I wrong about this? Should I create and cache myself? Are there hidden classes / methods that I am missing? Any help would be greatly appreciated.
source share