Tutorial :NHibernate Memory Leak


My company has an ASP.Net application that runs out of memory and throws out of memory exceptions after only a couple of days of activity by our customers. I am able to reproduce the error in our testing environment and I created a hang dump using adplus. When looking at the largest/most objects on the heap I noticed that we have over 500,000 NHibernate.SqlCommand.Parameter objects. This cannot be correct! We had 33 sessionfactories instantiated total and we have 1 sessionfactory per client database. The version of nhibernate we are using is

We have disabled second-level cache, query plan cache, and query cache. We still see 500,000 NHibernate.SqlCommand.Parameter in the memory dump.

Has any body seen this behavior?


We have a similar problem with our application (NHibernate, ODP.net on Windows 7). When we insert data into the database, we end up with a huge memory and handle leak:

for (int i=1;i<10000;i++)  {      using (var session = _sessionFactory.OpenSession();      {          var tx = session.OpenTransaction()          // insert a few rows into one table          tx.Commit()      }  }  

The only fix for the problem is to set Enlist=false in the connection string or use the OracleClientDriver instead of the OracleDataClientDriver. This problem did not happen in NHibernate 1.2. There was an even worse connection leak when we tried this with TransactionScope.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »