开发者

NHibernate holding on to a reference to data objects

开发者 https://www.devze.com 2023-02-09 17:58 出处:网络
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 reques

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开发者_如何学JAVA 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();
        }


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

0

精彩评论

暂无评论...
验证码 换一张
取 消