Reputation: 9541
I'm trying to work out where a lot of the memory in my app is going and while doing some profiling I'm noticing that any data objects that are loaded by NHibernate are hanging around once the request (is asp.net), and therefore session, has ended. Tracing it back, there are various things that seem to be doing it, like the "SingleTableEntityPersister" and the "StatefulPersistenceContext". I've disabled 2nd level caching for now, but they're still being held on to
Any ideas?
The session is being correctly disposed:
if (session != null)
{
if (session.Transaction != null && session.Transaction.IsActive)
{
session.Transaction.Rollback();
}
else
{
session.Flush();
}
session.Close();
session.Dispose();
}
Upvotes: 0
Views: 310
Reputation: 15217
NHibernate tracks all changes that are made to objects, that means that if you do:
user.FirstName = "name"
it will make the appropriate update in the DB.
But to track this NH needs references to all your objects. To get not tracked entities you can either use IStatelessSession
or remove object from the session using the Evict
method.
When session is disposed it releases all the tracked entities. So check if session is deleted properly and transaction is closed
Upvotes: 1