This is a code that causes memory leaks in our application.
ISessionConfigurer2 sessionConfigurer = new ESessionConfigurer();
sessionConfigurer.ConfigLocation = configLocation;
throw new Exception("something");
eclSession = sessionConfigurer.CreateSession2();
eclSession.ServiceName = serviceName;
FieldList lista = new FieldList();
lista.Add("username", new Field("username", user));
lista.Add("password", new Field("password", passwd));
eclSession.Login("WEB;", scriptNo, lista);
// run some actions on eclSession
This code is used in our windows service and is called thousands of times a day.
I've been able to profile that this code leaves classes from Remoting namespace in memory. Because of that we have to restart our windows service about every 10 days. Profilers show that classes from Remoting namespace go into Generation 2 and stay there forever. After some time GC starts doing full collections (Generation 2). It does not collect anything so it keeps trying over and over again thus causing high CPU usage. (We are not using Remoting in our code, so I'm 100% it's ESessionConfigurer's or ISession2's fault). As a quick check I changed the code to create only one ESessionConfigurer and one ISession2. It helped. I no longer can observe any memory leaks but I don't know if using one ESessionConfigurer and one ISession2 instance is thread safe. Our Windows service is multithreaded.
Is this known fact that ESessionConfigurer and ISession2 cause memory leaks?
Should I create one ESessionConfigurer and/or one ISession2 instance? Is it thread safe?
I have to add that we have to engines running so solution has to work with those two engines and enable load-balancing.